# HG changeset patch # User Bruno Haible # Date 1552069057 -3600 # Node ID 44073ad4207fa948b0465c2133820d26ee8b604b # Parent c43e83386661000678d1daba653d216f7826a287 unictype/numeric: Fix undefined behaviour. Reported by Jeffrey Walton . * 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. diff -r c43e83386661 -r 44073ad4207f ChangeLog --- a/ChangeLog Fri Mar 08 09:27:47 2019 -0800 +++ b/ChangeLog Fri Mar 08 19:17:37 2019 +0100 @@ -1,3 +1,13 @@ +2019-03-08 Bruno Haible + + unictype/numeric: Fix undefined behaviour. + Reported by Jeffrey Walton . + * 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 git-version-gen: fix --version copyright year diff -r c43e83386661 -r 44073ad4207f lib/unictype/bidi_of.c --- a/lib/unictype/bidi_of.c Fri Mar 08 09:27:47 2019 -0800 +++ b/lib/unictype/bidi_of.c Fri Mar 08 19:17:37 2019 +0100 @@ -39,7 +39,7 @@ 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; diff -r c43e83386661 -r 44073ad4207f lib/unictype/categ_of.c --- a/lib/unictype/categ_of.c Fri Mar 08 09:27:47 2019 -0800 +++ b/lib/unictype/categ_of.c Fri Mar 08 19:17:37 2019 +0100 @@ -39,7 +39,7 @@ 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; diff -r c43e83386661 -r 44073ad4207f lib/unictype/joininggroup_of.c --- a/lib/unictype/joininggroup_of.c Fri Mar 08 09:27:47 2019 -0800 +++ b/lib/unictype/joininggroup_of.c Fri Mar 08 19:17:37 2019 +0100 @@ -39,7 +39,7 @@ 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; diff -r c43e83386661 -r 44073ad4207f lib/unictype/numeric.c --- a/lib/unictype/numeric.c Fri Mar 08 09:27:47 2019 -0800 +++ b/lib/unictype/numeric.c Fri Mar 08 19:17:37 2019 +0100 @@ -39,8 +39,8 @@ 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;