Browse Source

uclibc-ng: fix overflow warning when compiling string/strchr in ILP32 mode on MIPS.

Signed-off-by: Evgeniy Manachkin <sfstudio@wi-cat.ru>
Evgeniy Manachkin 1 year ago
parent
commit
ff95fddd7b
2 changed files with 20 additions and 26 deletions
  1. 10 13
      libc/string/generic/strchr.c
  2. 10 13
      libc/string/generic/strchrnul.c

+ 10 - 13
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

+ 10 - 13
libc/string/generic/strchrnul.c

@@ -59,22 +59,19 @@ char *strchrnul (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