1
0
mirror of https://https.git.savannah.gnu.org/git/gnulib.git synced 2026-05-13 15:13:36 +00:00

quotearg: Avoid undefined behaviour.

Reported by Kirill Furman <kfurman@astralinux.ru> in
<https://lists.gnu.org/archive/html/bug-gnulib/2025-03/msg00037.html>.

* lib/quotearg.c (set_char_quoting): Use 'unsigned int', not 'int', for
doing bit mask operations.
This commit is contained in:
Bruno Haible
2025-03-10 17:28:33 +01:00
parent 69cbf3e2b3
commit 78c7fe8a85
2 changed files with 10 additions and 2 deletions

View File

@@ -1,3 +1,11 @@
2025-03-10 Bruno Haible <bruno@clisp.org>
quotearg: Avoid undefined behaviour.
Reported by Kirill Furman <kfurman@astralinux.ru> in
<https://lists.gnu.org/archive/html/bug-gnulib/2025-03/msg00037.html>.
* lib/quotearg.c (set_char_quoting): Use 'unsigned int', not 'int', for
doing bit mask operations.
2025-03-10 Bruno Haible <bruno@clisp.org>
getlogin, getlogin_r: Document limitation.

View File

@@ -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;
}