]> Savannah Git Hosting - gnulib.git/commitdiff
unictype/numeric: Fix undefined behaviour.
authorBruno Haible <bruno@clisp.org>
Fri, 8 Mar 2019 18:17:37 +0000 (19:17 +0100)
committerBruno Haible <bruno@clisp.org>
Fri, 8 Mar 2019 18:18:32 +0000 (19:18 +0100)
Reported by Jeffrey Walton <noloader@gmail.com>.

* lib/unictype/numeric.c (uc_numeric_value): Avoid undefined behaviour
on shift overflow, caught by "gcc -fsanitize=undefined".
* lib/unictype/bidi_of.c (uc_bidi_class): Add cast, for clarity.
* lib/unictype/categ_of.c (lookup_withtable): Likewise.
* lib/unictype/joininggroup_of.c (uc_joining_group): Likewise.

ChangeLog
lib/unictype/bidi_of.c
lib/unictype/categ_of.c
lib/unictype/joininggroup_of.c
lib/unictype/numeric.c

index e5ba15719ea61d9ec869890278fcb3602690f398..2e6126105d311acbe42fb0248b71b1c2b69fa70d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2019-03-08  Bruno Haible  <bruno@clisp.org>
+
+       unictype/numeric: Fix undefined behaviour.
+       Reported by Jeffrey Walton <noloader@gmail.com>.
+       * lib/unictype/numeric.c (uc_numeric_value): Avoid undefined behaviour
+       on shift overflow, caught by "gcc -fsanitize=undefined".
+       * lib/unictype/bidi_of.c (uc_bidi_class): Add cast, for clarity.
+       * lib/unictype/categ_of.c (lookup_withtable): Likewise.
+       * lib/unictype/joininggroup_of.c (uc_joining_group): Likewise.
+
 2019-03-05  Paul Eggert  <eggert@cs.ucla.edu>
 
        git-version-gen: fix --version copyright year
index 7e521177e67fefe3ea48b15f5e050853f8f3b9de..3db1f3a1b3090e468057a199a8250433e20c6961 100644 (file)
@@ -39,7 +39,7 @@ uc_bidi_class (ucs4_t uc)
               unsigned int index3 = ((uc & bidi_category_header_4) + lookup2) * 5;
               /* level3 contains 5-bit values, packed into 16-bit words.  */
               unsigned int lookup3 =
-                ((u_bidi_category.level3[index3>>4]
+                (((unsigned int) u_bidi_category.level3[index3>>4]
                   | ((unsigned int) u_bidi_category.level3[(index3>>4)+1] << 16))
                  >> (index3 % 16))
                 & 0x1f;
index a1e6762e7ef2892aaccac29031bdcc3d0d43b365..4c3f12716584d33cd51873fb28f0a6314d1b31bc 100644 (file)
@@ -39,7 +39,7 @@ lookup_withtable (ucs4_t uc)
               unsigned int index3 = ((uc & category_header_4) + lookup2) * 5;
               /* level3 contains 5-bit values, packed into 16-bit words.  */
               unsigned int lookup3 =
-                ((u_category.level3[index3>>4]
+                (((unsigned int) u_category.level3[index3>>4]
                   | ((unsigned int) u_category.level3[(index3>>4)+1] << 16))
                  >> (index3 % 16))
                 & 0x1f;
index db254a9b13f8afa87e72234ee3f1f18dc88c8b73..3b2a75e37c0e0daa2d317d1fe293a6b87836c554 100644 (file)
@@ -39,7 +39,7 @@ uc_joining_group (ucs4_t uc)
               unsigned int index3 = ((uc & joining_group_header_4) + lookup2) * 7;
               /* level3 contains 7-bit values, packed into 16-bit words.  */
               unsigned int lookup3 =
-                ((u_joining_group.level3[index3>>4]
+                (((unsigned int) u_joining_group.level3[index3>>4]
                   | ((unsigned int) u_joining_group.level3[(index3>>4)+1] << 16))
                  >> (index3 % 16))
                 & 0x7f;
index fd6eab9172e7a262fd2a873f4d86790460523a9b..a999183dd1aa481969f127f9596b9ec9dcb5cc59 100644 (file)
@@ -39,8 +39,8 @@ uc_numeric_value (ucs4_t uc)
               unsigned int index3 = ((uc & numeric_header_4) + lookup2) * 8;
               /* level3 contains 8-bit values, packed into 16-bit words.  */
               unsigned int lookup3 =
-                ((u_numeric.level3[index3>>4]
-                  | (u_numeric.level3[(index3>>4)+1] << 16))
+                (((unsigned int) u_numeric.level3[index3>>4]
+                  | ((unsigned int) u_numeric.level3[(index3>>4)+1] << 16))
                  >> (index3 % 16))
                 & 0xff;