This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[binutils][PATCH] Avoid zero-length VLAs.


Zero-length variable-length-arrays are not allowed in standard C99,
and perhaps more importantly, they cause ASAN to complain.  (See,
e.g., https://gcc.gnu.org/ml/gcc-patches/2013-09/msg00917.html.)

With this patch, the libiberty tests, including demangler-fuzzer, are
ASAN-clean.

- Brooks


P.S. I don't think I have commit access, so if this is OK, I'd
appreciate if the reviewer could commit it for me.  Thanks!

----
==== libiberty/ChangeLog ====
--- 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.
==== libiberty/cp-demangle.c ====
--- a/libiberty/cp-demangle.c
+++ b/libiberty/cp-demangle.c
@@ -4120,8 +4120,10 @@

   {
 #ifdef CP_DYNAMIC_ARRAYS
-    __extension__ struct d_saved_scope scopes[dpi.num_saved_scopes];
-    __extension__ struct d_print_template temps[dpi.num_copy_templates];
+    __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;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]