Re: [libiberty][PATCH] Avoid zero-length VLAs.
On Mon, Jul 11, 2016 at 4:27 PM, Ian Lance Taylorwrote: > On Mon, Jul 11, 2016 at 1:05 PM, Brooks Moses wrote: >> Ping? > > This is fine, but please add a comment explaining why the code avoids > 0-length VLAs. Thanks. Thanks! Committed as r238233. This is the comment I added: +/* 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]; - Brooks
Re: [libiberty][PATCH] Avoid zero-length VLAs.
On Mon, Jul 11, 2016 at 1:05 PM, Brooks Moseswrote: > 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 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 >> + >> + * cp-demangle.c (cplus_demangle_print_callback): Avoid zero-length >> + VLAs. >> + >> 2016-05-31 Alan Modra >> >> * 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;
Re: [libiberty][PATCH] Avoid zero-length VLAs.
Ping? (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 Moseswrote: > 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 > + > + * cp-demangle.c (cplus_demangle_print_callback): Avoid zero-length > + VLAs. > + > 2016-05-31 Alan Modra > > * 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;
[libiberty][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 libiberty/ChangeLog --- a/libiberty/ChangeLog +++ b/libiberty/ChangeLog @@ -1,3 +1,8 @@ +2016-06-12 Brooks Moses+ + * cp-demangle.c (cplus_demangle_print_callback): Avoid zero-length + VLAs. + 2016-05-31 Alan Modra * 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;