]> Savannah Git Hosting - gnulib.git/commitdiff
mbrtoc16: Fix undefined behaviour.
authorBruno Haible <bruno@clisp.org>
Tue, 10 Sep 2024 11:56:03 +0000 (13:56 +0200)
committerBruno Haible <bruno@clisp.org>
Tue, 17 Sep 2024 14:06:30 +0000 (16:06 +0200)
* lib/mbrtoc16.c (SET_EXTRA_STATE): Cast to 'unsigned int' before
shifting the bits to the positions 31..16.

ChangeLog
lib/mbrtoc16.c

index 9b25a979bdb14c295fd1166bea1f0a01b382d812..b9fb6391852990fc3d207164ca21d89027fe24af 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2024-09-10  Bruno Haible  <bruno@clisp.org>
+
+       mbrtoc16: Fix undefined behaviour.
+       * lib/mbrtoc16.c (SET_EXTRA_STATE): Cast to 'unsigned int' before
+       shifting the bits to the positions 31..16.
+
 2024-09-09  Bruno Haible  <bruno@clisp.org>
 
        string-desc: Fix undefined behaviour.
index 1fd0fbf24297d5ebc446621002ae7a0ddf65046b..96a33fa157e5a5c6ed6a69a5fe6ff560b7aedcc0 100644 (file)
@@ -45,7 +45,7 @@ static_assert (sizeof (mbstate_t) >= 4);
 /* mbstate_t is defined in <bits/types/__mbstate_t.h>.
    For more details, see glibc/iconv/skeleton.c.  */
 # define SET_EXTRA_STATE(ps, c16) \
-    ((ps)->__count |= (c16 << 16))
+    ((ps)->__count |= ((unsigned int) (c16) << 16))
 # define GET_EXTRA_STATE(ps) \
     (((unsigned int) (ps)->__count) >> 16)
 # define RESET_EXTRA_STATE(ps) \