]> Savannah Git Hosting - gnulib.git/commitdiff
unictype: avoid undefined left-shift behavior
authorDaiki Ueno <ueno@gnu.org>
Sat, 24 Jan 2015 02:11:34 +0000 (11:11 +0900)
committerDaiki Ueno <ueno@gnu.org>
Sat, 24 Jan 2015 02:12:48 +0000 (11:12 +0900)
* lib/unictype/bidi_of.c (uc_bidi_class): Building libunistring with
gcc's -fsanitize=shift and running its tests triggered:
  unictype/bidi_of.c:43:60: runtime error: left shift of 40167 by 16 \
    places cannot be represented in type 'int'
Cast LHS to 'unsigned int' after integer promotion.
* 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

index e0c12d32d9f414c3c7805521c4f4ed113f0761a3..a57bdd0bd04ab99724f751bb9aff177ee204747b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2015-01-24  Daiki Ueno  <ueno@gnu.org>
+
+       unictype: avoid undefined left-shift behavior
+       * lib/unictype/bidi_of.c (uc_bidi_class): Building libunistring with
+       gcc's -fsanitize=shift and running its tests triggered:
+         unictype/bidi_of.c:43:60: runtime error: left shift of 40167 by 16 \
+           places cannot be represented in type 'int'
+       Cast LHS to 'unsigned int' after integer promotion.
+       * lib/unictype/categ_of.c (lookup_withtable): Likewise.
+       * lib/unictype/joininggroup_of.c (uc_joining_group): Likewise.
+
 2015-01-20  Daiki Ueno  <ueno@gnu.org>
 
        libunistring: bump version of unitypes dependants
index aa27d2f9404bcf1eb1f34ac97095f0b831d7357e..4548ef5aa4fd3a497ad925884cd7b478e32b4ae1 100644 (file)
@@ -40,7 +40,7 @@ uc_bidi_class (ucs4_t uc)
               /* level3 contains 5-bit values, packed into 16-bit words.  */
               unsigned int lookup3 =
                 ((u_bidi_category.level3[index3>>4]
-                  | (u_bidi_category.level3[(index3>>4)+1] << 16))
+                  | ((unsigned int) u_bidi_category.level3[(index3>>4)+1] << 16))
                  >> (index3 % 16))
                 & 0x1f;
 
index 867dc09705261ca6dd4bb0bb57e3d7d5262a14bd..33f6c6c9293c4ff8869e6534e75290e3be3f51de 100644 (file)
@@ -40,7 +40,7 @@ lookup_withtable (ucs4_t uc)
               /* level3 contains 5-bit values, packed into 16-bit words.  */
               unsigned int lookup3 =
                 ((u_category.level3[index3>>4]
-                  | (u_category.level3[(index3>>4)+1] << 16))
+                  | ((unsigned int) u_category.level3[(index3>>4)+1] << 16))
                  >> (index3 % 16))
                 & 0x1f;
 
index 95845fbe43009789e3565f2c2b1c882d67e14b12..1626231f6de53d06f27c186e2c29365036778d41 100644 (file)
@@ -40,7 +40,7 @@ uc_joining_group (ucs4_t uc)
               /* level3 contains 7-bit values, packed into 16-bit words.  */
               unsigned int lookup3 =
                 ((u_joining_group.level3[index3>>4]
-                  | (u_joining_group.level3[(index3>>4)+1] << 16))
+                  | ((unsigned int) u_joining_group.level3[(index3>>4)+1] << 16))
                  >> (index3 % 16))
                 & 0x7f;