]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Don't assume that UCHAR_MAX <= INT_MAX.
authorBruno Haible <bruno@clisp.org>
Sat, 22 Jul 2006 14:36:52 +0000 (14:36 +0000)
committerBruno Haible <bruno@clisp.org>
Tue, 23 Jun 2009 10:13:38 +0000 (12:13 +0200)
gettext-tools/lib/ChangeLog
gettext-tools/lib/c-strcasecmp.c
gettext-tools/lib/c-strncasecmp.c

index 5d981a6b8290974db81a3f4840182ca50fa26442..e797373b85f54510cb4e624daeb6df98c79b86d0 100644 (file)
@@ -1,5 +1,9 @@
 2006-07-22  Bruno Haible  <bruno@clisp.org>
 
+       * c-strcasecmp.c: Update from gnulib. Don't assume that
+       UCHAR_MAX <= INT_MAX.
+       * c-strncasecmp.c: Likewise.
+
        * copy-file.c: Update from gnulib.
 
        * atexit.c: Update from gnulib.
index 2e3012e4d977265f5482ad8fb6a35c59b501f25c..00e3025943bab4028b42e023ba3f18f7717f74fa 100644 (file)
@@ -22,6 +22,8 @@
 /* Specification.  */
 #include "c-strcase.h"
 
+#include <limits.h>
+
 #include "c-ctype.h"
 
 int
@@ -47,5 +49,11 @@ c_strcasecmp (const char *s1, const char *s2)
     }
   while (c1 == c2);
 
-  return c1 - c2;
+  if (UCHAR_MAX <= INT_MAX)
+    return c1 - c2;
+  else
+    /* On machines where 'char' and 'int' are types of the same size, the
+       difference of two 'unsigned char' values - including the sign bit -
+       doesn't fit in an 'int'.  */
+    return (c1 > c2 ? 1 : c1 < c2 ? -1 : 0);
 }
index 33e8091b760f23bd6d421208f0732e1b1420b575..2d260efb67cef9de2b66dc502b5443eb6b874f68 100644 (file)
@@ -22,6 +22,8 @@
 /* Specification.  */
 #include "c-strcase.h"
 
+#include <limits.h>
+
 #include "c-ctype.h"
 
 int
@@ -47,5 +49,11 @@ c_strncasecmp (const char *s1, const char *s2, size_t n)
     }
   while (c1 == c2);
 
-  return c1 - c2;
+  if (UCHAR_MAX <= INT_MAX)
+    return c1 - c2;
+  else
+    /* On machines where 'char' and 'int' are types of the same size, the
+       difference of two 'unsigned char' values - including the sign bit -
+       doesn't fit in an 'int'.  */
+    return (c1 > c2 ? 1 : c1 < c2 ? -1 : 0);
 }