On Mon, Jul 11, 2016 at 1:05 PM, Brooks Moses <bmo...@google.com> wrote: > Ping?
This is fine, but please add a comment explaining why the code avoids 0-length VLAs. Thanks. Ian > (I suspect I should have added a libiberty maintainer to cc in the first > place.) > > On Mon, Jun 13, 2016 at 9:05 AM, Brooks Moses <bmo...@google.com> wrote: >> 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 >> >> >> ---- >> ==== libiberty/ChangeLog ==== >> --- a/libiberty/ChangeLog >> +++ b/libiberty/ChangeLog >> @@ -1,3 +1,8 @@ >> +2016-06-12 Brooks Moses <bmo...@google.com> >> + >> + * cp-demangle.c (cplus_demangle_print_callback): Avoid zero-length >> + VLAs. >> + >> 2016-05-31 Alan Modra <amo...@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;