summaryrefslogtreecommitdiff
path: root/lib/strcasecmp.c
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2005-10-11 12:47:44 +0000
committerBruno Haible <bruno@clisp.org>2005-10-11 12:47:44 +0000
commit47b3dd4ed61927c7dfc9ba870d9c0fa763ac57d8 (patch)
tree06e7d7a1aebcdacc7fd947d8501c05b21e632150 /lib/strcasecmp.c
parent3eef42323e03d43424480e77232cd118a035de62 (diff)
downloadgnulib-47b3dd4ed61927c7dfc9ba870d9c0fa763ac57d8.tar.gz
Avoid integer overflow on exotic platforms.
Diffstat (limited to 'lib/strcasecmp.c')
-rw-r--r--lib/strcasecmp.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/strcasecmp.c b/lib/strcasecmp.c
index 71f2eca7c9..c1bac0a5af 100644
--- a/lib/strcasecmp.c
+++ b/lib/strcasecmp.c
@@ -25,6 +25,7 @@
#include "strcase.h"
#include <ctype.h>
+#include <limits.h>
#if HAVE_MBRTOWC
# include "mbuiter.h"
@@ -93,6 +94,12 @@ 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);
}
}