annotate lib/unictype/joininggroup_of.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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14458
84e429ea8a0f New module 'unictype/joininggroup-of'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Arabic joining group of Unicode characters.
40057
b06060465f09 maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents: 19484
diff changeset
2 Copyright (C) 2011-2019 Free Software Foundation, Inc.
14458
84e429ea8a0f New module 'unictype/joininggroup-of'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3 Written by Bruno Haible <bruno@clisp.org>, 2011.
84e429ea8a0f New module 'unictype/joininggroup-of'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4
84e429ea8a0f New module 'unictype/joininggroup-of'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
5 This program is free software: you can redistribute it and/or modify it
84e429ea8a0f New module 'unictype/joininggroup-of'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6 under the terms of the GNU Lesser General Public License as published
84e429ea8a0f New module 'unictype/joininggroup-of'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
7 by the Free Software Foundation; either version 3 of the License, or
84e429ea8a0f New module 'unictype/joininggroup-of'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8 (at your option) any later version.
84e429ea8a0f New module 'unictype/joininggroup-of'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9
84e429ea8a0f New module 'unictype/joininggroup-of'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 This program is distributed in the hope that it will be useful,
84e429ea8a0f New module 'unictype/joininggroup-of'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
84e429ea8a0f New module 'unictype/joininggroup-of'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
84e429ea8a0f New module 'unictype/joininggroup-of'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13 Lesser General Public License for more details.
84e429ea8a0f New module 'unictype/joininggroup-of'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14
84e429ea8a0f New module 'unictype/joininggroup-of'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
15 You should have received a copy of the GNU Lesser General Public License
19190
9759915b2aca all: prefer https: URLs
Paul Eggert <eggert@cs.ucla.edu>
parents: 18626
diff changeset
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
14458
84e429ea8a0f New module 'unictype/joininggroup-of'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17
84e429ea8a0f New module 'unictype/joininggroup-of'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18 #include <config.h>
84e429ea8a0f New module 'unictype/joininggroup-of'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19
84e429ea8a0f New module 'unictype/joininggroup-of'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20 /* Specification. */
84e429ea8a0f New module 'unictype/joininggroup-of'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 #include "unictype.h"
84e429ea8a0f New module 'unictype/joininggroup-of'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22
17871
e6789c186343 libunistring: update to Unicode 6.1.0
Daiki Ueno <ueno@gnu.org>
parents: 17848
diff changeset
23 /* Define u_joining_group table. */
e6789c186343 libunistring: update to Unicode 6.1.0
Daiki Ueno <ueno@gnu.org>
parents: 17848
diff changeset
24 #include "joininggroup_of.h"
14458
84e429ea8a0f New module 'unictype/joininggroup-of'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25
84e429ea8a0f New module 'unictype/joininggroup-of'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26 int
84e429ea8a0f New module 'unictype/joininggroup-of'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27 uc_joining_group (ucs4_t uc)
84e429ea8a0f New module 'unictype/joininggroup-of'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28 {
17871
e6789c186343 libunistring: update to Unicode 6.1.0
Daiki Ueno <ueno@gnu.org>
parents: 17848
diff changeset
29 unsigned int index1 = uc >> joining_group_header_0;
e6789c186343 libunistring: update to Unicode 6.1.0
Daiki Ueno <ueno@gnu.org>
parents: 17848
diff changeset
30 if (index1 < joining_group_header_1)
e6789c186343 libunistring: update to Unicode 6.1.0
Daiki Ueno <ueno@gnu.org>
parents: 17848
diff changeset
31 {
e6789c186343 libunistring: update to Unicode 6.1.0
Daiki Ueno <ueno@gnu.org>
parents: 17848
diff changeset
32 int lookup1 = u_joining_group.level1[index1];
e6789c186343 libunistring: update to Unicode 6.1.0
Daiki Ueno <ueno@gnu.org>
parents: 17848
diff changeset
33 if (lookup1 >= 0)
e6789c186343 libunistring: update to Unicode 6.1.0
Daiki Ueno <ueno@gnu.org>
parents: 17848
diff changeset
34 {
e6789c186343 libunistring: update to Unicode 6.1.0
Daiki Ueno <ueno@gnu.org>
parents: 17848
diff changeset
35 unsigned int index2 = (uc >> joining_group_header_2) & joining_group_header_3;
e6789c186343 libunistring: update to Unicode 6.1.0
Daiki Ueno <ueno@gnu.org>
parents: 17848
diff changeset
36 int lookup2 = u_joining_group.level2[lookup1 + index2];
e6789c186343 libunistring: update to Unicode 6.1.0
Daiki Ueno <ueno@gnu.org>
parents: 17848
diff changeset
37 if (lookup2 >= 0)
e6789c186343 libunistring: update to Unicode 6.1.0
Daiki Ueno <ueno@gnu.org>
parents: 17848
diff changeset
38 {
e6789c186343 libunistring: update to Unicode 6.1.0
Daiki Ueno <ueno@gnu.org>
parents: 17848
diff changeset
39 unsigned int index3 = ((uc & joining_group_header_4) + lookup2) * 7;
e6789c186343 libunistring: update to Unicode 6.1.0
Daiki Ueno <ueno@gnu.org>
parents: 17848
diff changeset
40 /* level3 contains 7-bit values, packed into 16-bit words. */
e6789c186343 libunistring: update to Unicode 6.1.0
Daiki Ueno <ueno@gnu.org>
parents: 17848
diff changeset
41 unsigned int lookup3 =
40210
44073ad4207f unictype/numeric: Fix undefined behaviour.
Bruno Haible <bruno@clisp.org>
parents: 40057
diff changeset
42 (((unsigned int) u_joining_group.level3[index3>>4]
17880
18371cbd9692 unictype: avoid undefined left-shift behavior
Daiki Ueno <ueno@gnu.org>
parents: 17871
diff changeset
43 | ((unsigned int) u_joining_group.level3[(index3>>4)+1] << 16))
17871
e6789c186343 libunistring: update to Unicode 6.1.0
Daiki Ueno <ueno@gnu.org>
parents: 17848
diff changeset
44 >> (index3 % 16))
e6789c186343 libunistring: update to Unicode 6.1.0
Daiki Ueno <ueno@gnu.org>
parents: 17848
diff changeset
45 & 0x7f;
e6789c186343 libunistring: update to Unicode 6.1.0
Daiki Ueno <ueno@gnu.org>
parents: 17848
diff changeset
46
e6789c186343 libunistring: update to Unicode 6.1.0
Daiki Ueno <ueno@gnu.org>
parents: 17848
diff changeset
47 return lookup3;
e6789c186343 libunistring: update to Unicode 6.1.0
Daiki Ueno <ueno@gnu.org>
parents: 17848
diff changeset
48 }
e6789c186343 libunistring: update to Unicode 6.1.0
Daiki Ueno <ueno@gnu.org>
parents: 17848
diff changeset
49 }
e6789c186343 libunistring: update to Unicode 6.1.0
Daiki Ueno <ueno@gnu.org>
parents: 17848
diff changeset
50 }
14458
84e429ea8a0f New module 'unictype/joininggroup-of'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
51 return UC_JOINING_GROUP_NONE;
84e429ea8a0f New module 'unictype/joininggroup-of'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
52 }