Mercurial > hg > octave-nkf > gnulib-hg
changeset 17646:0a7fbe4650ff
strftime: wrap macros in "do {...} while(0)"
* lib/strftime.c (DO_NUMBER): Wrap multi-statement code block of
this macro in "do {...} while(0)" to prevent false use as a
single statement, e.g., in an un-braced "{}" else-block.
(DO_SIGNED_NUMBER, DO_TZ_OFFSET, DO_NUMBER_SPACEPAD): Likewise.
(strftime_case_): Remove 'else' after 'goto' - which was the
only non-fatal, un-braced use of one of the above macros.
Spotted by coverity (NESTING_INDENT_MISMATCH).
author | Bernhard Voelker <mail@bernhard-voelker.de> |
---|---|
date | Wed, 26 Mar 2014 02:45:58 +0100 |
parents | 23530dae897f |
children | ae63f4dd18f3 |
files | ChangeLog lib/strftime.c |
diffstat | 2 files changed, 45 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2014-03-26 Bernhard Voelker <mail@bernhard-voelker.de> + + strftime: wrap macros in "do {...} while(0)" + * lib/strftime.c (DO_NUMBER): Wrap multi-statement code block of + this macro in "do {...} while(0)" to prevent false use as a + single statement, e.g., in an un-braced "{}" else-block. + (DO_SIGNED_NUMBER, DO_TZ_OFFSET, DO_NUMBER_SPACEPAD): Likewise. + (strftime_case_): Remove 'else' after 'goto' - which was the + only non-fatal, un-braced use of one of the above macros. + Spotted by coverity (NESTING_INDENT_MISMATCH). + 2014-03-26 Bernhard Voelker <mail@bernhard-voelker.de> modechange: avoid memory leaks for invalid octal modes
--- a/lib/strftime.c +++ b/lib/strftime.c @@ -681,24 +681,44 @@ switch (format_char) { #define DO_NUMBER(d, v) \ - digits = d; \ - number_value = v; goto do_number + do \ + { \ + digits = d; \ + number_value = v; \ + goto do_number; \ + } \ + while (0) #define DO_SIGNED_NUMBER(d, negative, v) \ - digits = d; \ - negative_number = negative; \ - u_number_value = v; goto do_signed_number + do \ + { \ + digits = d; \ + negative_number = negative; \ + u_number_value = v; \ + goto do_signed_number; \ + } \ + while (0) /* The mask is not what you might think. When the ordinal i'th bit is set, insert a colon before the i'th digit of the time zone representation. */ #define DO_TZ_OFFSET(d, negative, mask, v) \ - digits = d; \ - negative_number = negative; \ - tz_colon_mask = mask; \ - u_number_value = v; goto do_tz_offset + do \ + { \ + digits = d; \ + negative_number = negative; \ + tz_colon_mask = mask; \ + u_number_value = v; \ + goto do_tz_offset; \ + } \ + while (0) #define DO_NUMBER_SPACEPAD(d, v) \ - digits = d; \ - number_value = v; goto do_number_spacepad + do \ + { \ + digits = d; \ + number_value = v; \ + goto do_number_spacepad; \ + } \ + while (0) case L_('%'): if (modifier != 0) @@ -1265,9 +1285,9 @@ } if (modifier == L_('O')) goto bad_format; - else - DO_SIGNED_NUMBER (4, tp->tm_year < -TM_YEAR_BASE, - tp->tm_year + (unsigned int) TM_YEAR_BASE); + + DO_SIGNED_NUMBER (4, tp->tm_year < -TM_YEAR_BASE, + tp->tm_year + (unsigned int) TM_YEAR_BASE); case L_('y'): if (modifier == L_('E'))