aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libiberty/ChangeLog5
-rw-r--r--libiberty/cp-demangle.c8
2 files changed, 11 insertions, 2 deletions
diff --git a/libiberty/ChangeLog b/libiberty/ChangeLog
index d6b200e0ef2..45b312bed5c 100644
--- a/libiberty/ChangeLog
+++ b/libiberty/ChangeLog
@@ -1,3 +1,8 @@
+2016-06-12 Brooks Moses <bmoses@google.com>
+
+ * cp-demangle.c (cplus_demangle_print_callback): Avoid zero-length
+ VLAs.
+
2016-05-31 Alan Modra <amodra@gmail.com>
* xmemdup.c (xmemdup): Use xmalloc rather than xcalloc.
diff --git a/libiberty/cp-demangle.c b/libiberty/cp-demangle.c
index 09d64699466..7f664b9c5c0 100644
--- a/libiberty/cp-demangle.c
+++ b/libiberty/cp-demangle.c
@@ -4128,8 +4128,12 @@ cplus_demangle_print_callback (int options,
{
#ifdef CP_DYNAMIC_ARRAYS
- __extension__ struct d_saved_scope scopes[dpi.num_saved_scopes];
- __extension__ struct d_print_template temps[dpi.num_copy_templates];
+ /* Avoid zero-length VLAs, which are prohibited by the C99 standard
+ and flagged as errors by Address Sanitizer. */
+ __extension__ struct d_saved_scope scopes[(dpi.num_saved_scopes > 0)
+ ? dpi.num_saved_scopes : 1];
+ __extension__ struct d_print_template temps[(dpi.num_copy_templates > 0)
+ ? dpi.num_copy_templates : 1];
dpi.saved_scopes = scopes;
dpi.copy_templates = temps;