Mercurial > gnulib
comparison lib/unictype/numeric.c @ 40210:44073ad4207f
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.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Fri, 08 Mar 2019 19:17:37 +0100 |
parents | b06060465f09 |
children |
comparison
equal
deleted
inserted
replaced
40209:c43e83386661 | 40210:44073ad4207f |
---|---|
37 if (lookup2 >= 0) | 37 if (lookup2 >= 0) |
38 { | 38 { |
39 unsigned int index3 = ((uc & numeric_header_4) + lookup2) * 8; | 39 unsigned int index3 = ((uc & numeric_header_4) + lookup2) * 8; |
40 /* level3 contains 8-bit values, packed into 16-bit words. */ | 40 /* level3 contains 8-bit values, packed into 16-bit words. */ |
41 unsigned int lookup3 = | 41 unsigned int lookup3 = |
42 ((u_numeric.level3[index3>>4] | 42 (((unsigned int) u_numeric.level3[index3>>4] |
43 | (u_numeric.level3[(index3>>4)+1] << 16)) | 43 | ((unsigned int) u_numeric.level3[(index3>>4)+1] << 16)) |
44 >> (index3 % 16)) | 44 >> (index3 % 16)) |
45 & 0xff; | 45 & 0xff; |
46 | 46 |
47 return u_numeric_values[lookup3]; | 47 return u_numeric_values[lookup3]; |
48 } | 48 } |