diff options
author | Evgeniy Manachkin <sfstudio@mail.ru> | 2022-11-30 15:06:51 +0500 |
---|---|---|
committer | Waldemar Brodkorb <wbx@openadk.org> | 2022-12-07 10:59:16 +0100 |
commit | ff95fddd7b25d207f41af05052a0b4de88322e35 (patch) | |
tree | ee834a5f2bc32303ced89239dd3a8084e31a26f0 /libc/string/generic/strchr.c | |
parent | 0a5466d8d53bc8045ff56ff76cc1880aa85761c2 (diff) |
uclibc-ng: fix overflow warning when compiling string/strchr in ILP32 mode on MIPS.
Signed-off-by: Evgeniy Manachkin <sfstudio@wi-cat.ru>
Diffstat (limited to 'libc/string/generic/strchr.c')
-rw-r--r-- | libc/string/generic/strchr.c | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/libc/string/generic/strchr.c b/libc/string/generic/strchr.c index 321d2b8c3..b34884d67 100644 --- a/libc/string/generic/strchr.c +++ b/libc/string/generic/strchr.c @@ -60,22 +60,19 @@ char *strchr (const char *s, int c_in) The 1-bits make sure that carries propagate to the next 0-bit. The 0-bits provide holes for carries to fall into. */ - switch (sizeof (longword)) - { - case 4: magic_bits = 0x7efefeffL; break; - case 8: magic_bits = ((0x7efefefeL << 16) << 16) | 0xfefefeffL; break; - default: - abort (); - } - /* Set up a longword, each of whose bytes is C. */ +#if __WORDSIZE == 32 + magic_bits = 0x7efefeffL; charmask = c | (c << 8); charmask |= charmask << 16; - if (sizeof (longword) > 4) - /* Do the shift in two steps to avoid a warning if long has 32 bits. */ - charmask |= (charmask << 16) << 16; - if (sizeof (longword) > 8) - abort (); +#elif __WORDSIZE == 64 + magic_bits = ((0x7efefefeL << 16) << 16) | 0xfefefeffL; + charmask = c | (c << 8); + charmask |= charmask << 16; + charmask |= (charmask << 16) << 16; +#else + #error unexpected integer size strchr() +#endif /* Instead of the traditional loop which tests each character, we will test a longword at a time. The tricky part is testing |