]> Savannah Git Hosting - gnulib.git/commitdiff
quotearg: Avoid undefined behaviour.
authorBruno Haible <bruno@clisp.org>
Mon, 10 Mar 2025 16:28:33 +0000 (17:28 +0100)
committerBruno Haible <bruno@clisp.org>
Tue, 1 Apr 2025 14:29:52 +0000 (16:29 +0200)
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.

ChangeLog
lib/quotearg.c

index 3f80b9a2b470552b6daadc4235b3348d4005239f..329f4e424e91ece86b3f49cad8118f2cf32fd2ac 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -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-09  Bruno Haible  <bruno@clisp.org>
 
        getlogin_r: Work around musl bug.
index d7b549e4786ac00fad6865e92c31d064dbe75713..6bf0f5a905779dd9d4583d66b310bc51d9e0f9b5 100644 (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;
 }