Blame SOURCES/valgrind-3.14.0-wcsncmp.patch

560544
commit 5fdabb72fdcba6bcf788eaa19c1ee557c13b8a7a
560544
Author: Mark Wielaard <mark@klomp.org>
560544
Date:   Sat Dec 1 23:54:40 2018 +0100
560544
560544
    Bug 401627 - Add wcsncmp override and testcase.
560544
    
560544
    glibc 2.28 added an avx2 optimized variant of wstrncmp which memcheck
560544
    cannot proof correct. Add a simple override in vg_replace_strmem.c.
560544
560544
diff --git a/memcheck/tests/wcs.c b/memcheck/tests/wcs.c
560544
index 15730ad..538304b 100644
560544
--- a/memcheck/tests/wcs.c
560544
+++ b/memcheck/tests/wcs.c
560544
@@ -1,5 +1,6 @@
560544
-// Uses various wchar_t * functions that have hand written SSE assembly
560544
-// implementations in glibc. wcslen, wcscpy, wcscmp, wcsrchr, wcschr.
560544
+// Uses various wchar_t * functions that have hand written SSE and/or AVX2
560544
+// assembly implementations in glibc.
560544
+// wcslen, wcscpy, wcscmp, wcsncmp, wcsrchr, wcschr.
560544
 
560544
 #include <stdio.h>
560544
 #include <stdlib.h>
560544
@@ -18,6 +19,8 @@ int main(int argc, char **argv)
560544
   c = wcscpy (b, a);
560544
 
560544
   fprintf (stderr, "wcscmp equal: %d\n", wcscmp (a, b)); // wcscmp equal: 0
560544
+  fprintf (stderr,
560544
+	   "wcsncmp equal: %d\n", wcsncmp (a, b, l)); // wcsncmp equal: 0
560544
 
560544
   d = wcsrchr (a, L'd');
560544
   e = wcschr (a, L'd');
560544
diff --git a/memcheck/tests/wcs.stderr.exp b/memcheck/tests/wcs.stderr.exp
560544
index 41d74c8..d5b5959 100644
560544
--- a/memcheck/tests/wcs.stderr.exp
560544
+++ b/memcheck/tests/wcs.stderr.exp
560544
@@ -1,3 +1,4 @@
560544
 wcslen: 53
560544
 wcscmp equal: 0
560544
+wcsncmp equal: 0
560544
 wcsrchr == wcschr: 1
560544
diff --git a/shared/vg_replace_strmem.c b/shared/vg_replace_strmem.c
560544
index d6927f0..89a7dcc 100644
560544
--- a/shared/vg_replace_strmem.c
560544
+++ b/shared/vg_replace_strmem.c
560544
@@ -103,6 +103,7 @@
560544
    20420 STPNCPY
560544
    20430 WMEMCHR
560544
    20440 WCSNLEN
560544
+   20450 WSTRNCMP
560544
 */
560544
 
560544
 #if defined(VGO_solaris)
560544
@@ -1927,6 +1928,36 @@ static inline void my_exit ( int x )
560544
  WCSCMP(VG_Z_LIBC_SONAME,          wcscmp)
560544
 #endif
560544
 
560544
+/*---------------------- wcsncmp ----------------------*/
560544
+
560544
+// This is a wchar_t equivalent to strncmp.  We don't
560544
+// have wchar_t available here, but in the GNU C Library
560544
+// wchar_t is always 32 bits wide and wcsncmp uses signed
560544
+// comparison, not unsigned as in strncmp function.
560544
+
560544
+#define WCSNCMP(soname, fnname) \
560544
+   int VG_REPLACE_FUNCTION_EZU(20450,soname,fnname) \
560544
+          ( const Int* s1, const Int* s2, SizeT nmax ); \
560544
+   int VG_REPLACE_FUNCTION_EZU(20450,soname,fnname) \
560544
+          ( const Int* s1, const Int* s2, SizeT nmax ) \
560544
+   { \
560544
+      SizeT n = 0; \
560544
+      while (True) { \
560544
+         if (n >= nmax) return 0; \
560544
+         if (*s1 == 0 && *s2 == 0) return 0; \
560544
+         if (*s1 == 0) return -1; \
560544
+         if (*s2 == 0) return 1; \
560544
+         \
560544
+         if (*s1 < *s2) return -1; \
560544
+         if (*s1 > *s2) return 1; \
560544
+         \
560544
+         s1++; s2++; n++; \
560544
+      } \
560544
+   }
560544
+#if defined(VGO_linux)
560544
+ WCSNCMP(VG_Z_LIBC_SONAME,          wcsncmp)
560544
+#endif
560544
+
560544
 /*---------------------- wcscpy ----------------------*/
560544
 
560544
 // This is a wchar_t equivalent to strcpy.  We don't