From: Daiki Ueno <ueno@gnu.org>
Date: Sat, 24 Jan 2015 02:11:34 +0000 (+0900)
Subject: unictype: avoid undefined left-shift behavior
X-Git-Tag: v1.0~7178
X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=bb41ff0b77820134bd47640ba93249dd4a1b01c4;p=gnulib.git

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.
---

diff --git a/ChangeLog b/ChangeLog
index e0c12d32d9..a57bdd0bd0 100644
--- 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
diff --git a/lib/unictype/bidi_of.c b/lib/unictype/bidi_of.c
index aa27d2f940..4548ef5aa4 100644
--- a/lib/unictype/bidi_of.c
+++ b/lib/unictype/bidi_of.c
@@ -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;
 
diff --git a/lib/unictype/categ_of.c b/lib/unictype/categ_of.c
index 867dc09705..33f6c6c929 100644
--- a/lib/unictype/categ_of.c
+++ b/lib/unictype/categ_of.c
@@ -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;
 
diff --git a/lib/unictype/joininggroup_of.c b/lib/unictype/joininggroup_of.c
index 95845fbe43..1626231f6d 100644
--- a/lib/unictype/joininggroup_of.c
+++ b/lib/unictype/joininggroup_of.c
@@ -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;