[PATCH] [tsan] Fix strcmp/strncmp interceptor return value
Matthew Dempsky
matthew at dempsky.org
Thu Jul 11 10:19:16 PDT 2013
C99 says memcmp, strcmp, and strncmp return the difference of
character values interpreted as unsigned char values. tsan's memcmp
interceptor already does this correctly, but strcmp and strncmp do
not.
Untested patch below.
Index: tsan_interceptors.cc
===================================================================
--- tsan_interceptors.cc (revision 186094)
+++ tsan_interceptors.cc (working copy)
@@ -599,7 +599,7 @@
}
MemoryAccessRange(thr, pc, (uptr)s1, len + 1, false);
MemoryAccessRange(thr, pc, (uptr)s2, len + 1, false);
- return s1[len] - s2[len];
+ return (unsigned char)s1[len] - (unsigned char)s2[len];
}
TSAN_INTERCEPTOR(int, strncmp, const char *s1, const char *s2, uptr n) {
@@ -611,7 +611,7 @@
}
MemoryAccessRange(thr, pc, (uptr)s1, len < n ? len + 1 : n, false);
MemoryAccessRange(thr, pc, (uptr)s2, len < n ? len + 1 : n, false);
- return len == n ? 0 : s1[len] - s2[len];
+ return len == n ? 0 : (unsigned char)s1[len] - (unsigned char)s2[len];
}
TSAN_INTERCEPTOR(void*, memchr, void *s, int c, uptr n) {
More information about the llvm-commits
mailing list