about summary refs log tree commit diff
path: root/string/test-strcmp.c
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2014-04-30 12:57:51 -0700
committerDavid S. Miller <davem@davemloft.net>2014-05-01 16:22:39 -0400
commit726978490fe8a26a1343ac314d00dd48924a1799 (patch)
tree361eea745dd553115f6a4cde9a32618a885d6114 /string/test-strcmp.c
parentcec24099fb06c785b89119aab93940312c2949ba (diff)
downloadglibc-726978490fe8a26a1343ac314d00dd48924a1799.tar.gz
glibc-726978490fe8a26a1343ac314d00dd48924a1799.tar.xz
glibc-726978490fe8a26a1343ac314d00dd48924a1799.zip
Fix v9/64-bit strcmp when string ends in multiple zero bytes.
	[BZ #16885]
	* sysdeps/sparc/sparc64/strcmp.S: Fix end comparison handling when
	multiple zero bytes exist at the end of a string.
	Reported by Aurelien Jarno <aurelien@aurel32.net>

	* string/test-strcmp.c (check): Add explicit test for situations where
	there are multiple zero bytes after the first.
Diffstat (limited to 'string/test-strcmp.c')
-rw-r--r--string/test-strcmp.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/string/test-strcmp.c b/string/test-strcmp.c
index f186fd6cd9..73101569a0 100644
--- a/string/test-strcmp.c
+++ b/string/test-strcmp.c
@@ -353,6 +353,34 @@ check (void)
 		FOR_EACH_IMPL (impl, 0)
 		check_result (impl, s1 + i1, s2 + i2, exp_result);
       }
+
+  /* Test cases where there are multiple zero bytes after the first.  */
+
+  for (size_t i = 0; i < 16 + 1; i++)
+    {
+      s1[i] = 0x00;
+      s2[i] = 0x00;
+    }
+
+  for (size_t i = 0; i < 16; i++)
+    {
+      int exp_result;
+
+      for (int val = 0x01; val < 0x100; val++)
+	{
+	  for (size_t j = 0; j < i; j++)
+	    {
+	      s1[j] = val;
+	      s2[j] = val;
+	    }
+
+	  s2[i] = val;
+
+	  exp_result = SIMPLE_STRCMP (s1, s2);
+	  FOR_EACH_IMPL (impl, 0)
+	    check_result (impl, s1, s2, exp_result);
+	}
+    }
 }