Mercurial > gnulib
changeset 17544:dfc32d9dd325
quotearg: don't attempt to store 1 << 31 into an "int"
* lib/quotearg.c (quotearg_buffer_restyled): Building coreutils with
gcc's new -fsanitize=undefined and running its tests triggered some
new test failures due to undefined behavior, all with this diagnostic:
lib/quotearg.c:629:62: runtime error: left shift of 1 by 31 places \
cannot be represented in type int
Rather than shifting "1" left to form a mask, shift the bits right and
simply use "1" as the mask.
Co-authored-by: Paul Eggert <eggert@cs.ucla.edu>
author | Jim Meyering <meyering@fb.com> |
---|---|
date | Mon, 18 Nov 2013 17:35:01 -0800 |
parents | 9de3500cef0c |
children | c8e7fccb3b6d |
files | ChangeLog lib/quotearg.c |
diffstat | 2 files changed, 13 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Thu Nov 21 12:12:45 2013 -0800 +++ b/ChangeLog Mon Nov 18 17:35:01 2013 -0800 @@ -1,3 +1,15 @@ +2013-11-18 Jim Meyering <meyering@fb.com> + and Paul Eggert <eggert@cs.ucla.edu> + + quotearg: don't attempt to store 1 << 31 into an "int" + * lib/quotearg.c (quotearg_buffer_restyled): Building coreutils with + gcc's new -fsanitize=undefined and running its tests triggered some + new test failures due to undefined behavior, all with this diagnostic: + lib/quotearg.c:629:62: runtime error: left shift of 1 by 31 places \ + cannot be represented in type int + Rather than shifting "1" left to form a mask, shift the bits right and + simply use "1" as the mask. + 2013-11-21 Paul Eggert <eggert@cs.ucla.edu> error: depend on stdio
--- a/lib/quotearg.c Thu Nov 21 12:12:45 2013 -0800 +++ b/lib/quotearg.c Mon Nov 18 17:35:01 2013 -0800 @@ -626,7 +626,7 @@ if (! ((backslash_escapes || elide_outer_quotes) && quote_these_too - && quote_these_too[c / INT_BITS] & (1 << (c % INT_BITS))) + && quote_these_too[c / INT_BITS] >> (c % INT_BITS) & 1) && !is_right_quote) goto store_c;