From: Bruno Haible Date: Mon, 10 Mar 2025 16:28:33 +0000 (+0100) Subject: quotearg: Avoid undefined behaviour. X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=78c7fe8a85dda15f145511f9acf8580e795e40bc;p=gnulib.git quotearg: Avoid undefined behaviour. Reported by Kirill Furman in . * lib/quotearg.c (set_char_quoting): Use 'unsigned int', not 'int', for doing bit mask operations. --- diff --git a/ChangeLog b/ChangeLog index fbda8372e7..52a6f16192 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2025-03-10 Bruno Haible + + quotearg: Avoid undefined behaviour. + Reported by Kirill Furman in + . + * lib/quotearg.c (set_char_quoting): Use 'unsigned int', not 'int', for + doing bit mask operations. + 2025-03-10 Bruno Haible getlogin, getlogin_r: Document limitation. diff --git a/lib/quotearg.c b/lib/quotearg.c index a31ea3d100..a587cd5b45 100644 --- a/lib/quotearg.c +++ b/lib/quotearg.c @@ -147,8 +147,8 @@ set_char_quoting (struct quoting_options *o, char c, int i) unsigned int *p = (o ? o : &default_quoting_options)->quote_these_too + uc / INT_BITS; int shift = uc % INT_BITS; - int r = (*p >> shift) & 1; - *p ^= ((i & 1) ^ r) << shift; + unsigned int r = (*p >> shift) & 1; + *p ^= ((i & 1U) ^ r) << shift; return r; }