about summary refs log tree commit diff
path: root/wcsmbs/wcsncmp.c
diff options
context:
space:
mode:
authorStefan Liebler <stli@linux.vnet.ibm.com>2015-04-13 21:23:10 +0200
committerAndreas Krebbel <krebbel@linux.vnet.ibm.com>2015-04-13 21:25:04 +0200
commit920a0395ba9fa5949ec87aaf5daa0259da16749d (patch)
treef590d2c50132feb89be712a38754faaf3c7f45c6 /wcsmbs/wcsncmp.c
parentde8aadd52c97f9a04d5e8709b16dc5baf9292a09 (diff)
downloadglibc-920a0395ba9fa5949ec87aaf5daa0259da16749d.tar.gz
glibc-920a0395ba9fa5949ec87aaf5daa0259da16749d.tar.xz
glibc-920a0395ba9fa5949ec87aaf5daa0259da16749d.zip
Use correct signedness in wcsncmp
	[BZ #18206]
	* wcsmbs/wcsncmp.c (wcsncmp): Compare as wchar_t, not wint_t.
	  Use signed comparision instead of substraction to avoid
	  overflow bug.
	* localedata/tests-mbwc/tst_wcsncmp.c (tst_wcsncmp):
	  Take the sign of ret.
	* localedata/tests-mbwc/dat_wcsncmp.c (tst_wcsncmp_loc):
	  Do not expect precise return values. Only the sign matters.
	* wcsmbs/Makefile (strop-tests): Add wcsncmp.
	* wcsmbs/test-wcsncmp.c: New File.
	* string/test-strncmp.c: Add wcsncmp support.
Diffstat (limited to 'wcsmbs/wcsncmp.c')
-rw-r--r--wcsmbs/wcsncmp.c36
1 files changed, 18 insertions, 18 deletions
diff --git a/wcsmbs/wcsncmp.c b/wcsmbs/wcsncmp.c
index 59e003b857..e083ad8174 100644
--- a/wcsmbs/wcsncmp.c
+++ b/wcsmbs/wcsncmp.c
@@ -29,42 +29,42 @@ wcsncmp (s1, s2, n)
      const wchar_t *s2;
      size_t n;
 {
-  wint_t c1 = L'\0';
-  wint_t c2 = L'\0';
+  wchar_t c1 = L'\0';
+  wchar_t c2 = L'\0';
 
   if (n >= 4)
     {
       size_t n4 = n >> 2;
       do
 	{
-	  c1 = (wint_t) *s1++;
-	  c2 = (wint_t) *s2++;
+	  c1 = *s1++;
+	  c2 = *s2++;
 	  if (c1 == L'\0' || c1 != c2)
-	    return c1 - c2;
-	  c1 = (wint_t) *s1++;
-	  c2 = (wint_t) *s2++;
+	    return c1 > c2 ? 1 : (c1 < c2 ? -1 : 0);
+	  c1 = *s1++;
+	  c2 = *s2++;
 	  if (c1 == L'\0' || c1 != c2)
-	    return c1 - c2;
-	  c1 = (wint_t) *s1++;
-	  c2 = (wint_t) *s2++;
+	    return c1 > c2 ? 1 : (c1 < c2 ? -1 : 0);
+	  c1 = *s1++;
+	  c2 = *s2++;
 	  if (c1 == L'\0' || c1 != c2)
-	    return c1 - c2;
-	  c1 = (wint_t) *s1++;
-	  c2 = (wint_t) *s2++;
+	    return c1 > c2 ? 1 : (c1 < c2 ? -1 : 0);
+	  c1 = *s1++;
+	  c2 = *s2++;
 	  if (c1 == L'\0' || c1 != c2)
-	    return c1 - c2;
+	    return c1 > c2 ? 1 : (c1 < c2 ? -1 : 0);
 	} while (--n4 > 0);
       n &= 3;
     }
 
   while (n > 0)
     {
-      c1 = (wint_t) *s1++;
-      c2 = (wint_t) *s2++;
+      c1 = *s1++;
+      c2 = *s2++;
       if (c1 == L'\0' || c1 != c2)
-	return c1 - c2;
+	return c1 > c2 ? 1 : (c1 < c2 ? -1 : 0);
       n--;
     }
 
-  return c1 - c2;
+  return 0;
 }