<div dir="ltr">Either way works for me.</div><br><div class="gmail_quote"><div dir="ltr">On Mon, Nov 14, 2016 at 1:13 PM Reid Kleckner <<a href="mailto:rnk@google.com">rnk@google.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="gmail_msg">I like having a separate test case for each interceptor, so that if we start failing to intercept one function, only one test fails for that function.</div><div class="gmail_extra gmail_msg"><br class="gmail_msg"><div class="gmail_quote gmail_msg">On Mon, Nov 14, 2016 at 12:36 PM, Vitaly Buka <span dir="ltr" class="gmail_msg"><<a href="mailto:vitalybuka@google.com" class="gmail_msg" target="_blank">vitalybuka@google.com</a>></span> wrote:<br class="gmail_msg"><blockquote class="gmail_quote gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="gmail_msg">maybe better just redefine <span style="color:rgb(33,33,33)" class="gmail_msg">strncasecmp to </span><font color="#212121" class="gmail_msg">strncmp for Windows inside of the test to avoid code duplication?</font></div><div class="m_-3365828223990859221HOEnZb gmail_msg"><div class="m_-3365828223990859221h5 gmail_msg"><br class="gmail_msg"><div class="gmail_quote gmail_msg"><div dir="ltr" class="gmail_msg">On Mon, Nov 14, 2016 at 9:47 AM Reid Kleckner <<a href="mailto:rnk@google.com" class="gmail_msg" target="_blank">rnk@google.com</a>> wrote:<br class="gmail_msg"></div><blockquote class="gmail_quote gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">Windows doesn't have strncasecmp. I have a hack to make the test pass, but maybe it would be better to split the test into strncmp and strncasecmp and XFAIL the strncasecmp one.</div><div class="gmail_extra m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg"><br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg"><div class="gmail_quote m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">On Fri, Nov 11, 2016 at 8:32 PM, Vitaly Buka via llvm-commits <span dir="ltr" class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg"><<a href="mailto:llvm-commits@lists.llvm.org" class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg"><blockquote class="gmail_quote m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: vitalybuka<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
Date: Fri Nov 11 22:32:31 2016<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
New Revision: 286708<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=286708&view=rev" rel="noreferrer" class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project?rev=286708&view=rev</a><br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
Log:<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
[asan] Fix strncmp and strncasecmp interceptors<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
Summary:<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
In non-strict mode we will check memory access for both strings from beginning<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
to either:<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
1. 0-char<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
2. size<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
3. different chars<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
In strict mode we will check from beginning to either:<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
1. 0-char<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
2. size<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
Previously in strict mode we always checked up to the 0-char.<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
Reviewers: kcc, eugenis<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
Subscribers: llvm-commits, kubabrecka<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
Differential Revision: <a href="https://reviews.llvm.org/D26574" rel="noreferrer" class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg" target="_blank">https://reviews.llvm.org/D26574</a><br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
Modified:<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
compiler-rt/trunk/test/asan/TestCases/strncmp_strict.c<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc?rev=286708&r1=286707&r2=286708&view=diff" rel="noreferrer" class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc?rev=286708&r1=286707&r2=286708&view=diff</a><br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
==============================================================================<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc (original)<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc Fri Nov 11 22:32:31 2016<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
@@ -304,8 +304,14 @@ INTERCEPTOR(int, strncmp, const char *s1<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
c2 = (unsigned char)s2[i];<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
if (c1 != c2 || c1 == '\0') break;<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
}<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
- COMMON_INTERCEPTOR_READ_STRING(ctx, s1, Min(i + 1, size));<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
- COMMON_INTERCEPTOR_READ_STRING(ctx, s2, Min(i + 1, size));<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+ uptr i1 = i;<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+ uptr i2 = i;<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+ if (common_flags()->strict_string_checks) {<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+ for (; i1 < size && s1[i1]; i1++) {}<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+ for (; i2 < size && s2[i2]; i2++) {}<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+ }<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+ COMMON_INTERCEPTOR_READ_RANGE((ctx), (s1), Min(i1 + 1, size));<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+ COMMON_INTERCEPTOR_READ_RANGE((ctx), (s2), Min(i2 + 1, size));<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
int result = CharCmpX(c1, c2);<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
CALL_WEAK_INTERCEPTOR_HOOK(__sanitizer_weak_hook_strncmp, GET_CALLER_PC(), s1,<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
s2, size, result);<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
@@ -348,24 +354,30 @@ INTERCEPTOR(int, strcasecmp, const char<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
}<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
DECLARE_WEAK_INTERCEPTOR_HOOK(__sanitizer_weak_hook_strncasecmp, uptr called_pc,<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
- const char *s1, const char *s2, uptr n,<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+ const char *s1, const char *s2, uptr size,<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
int result)<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
-INTERCEPTOR(int, strncasecmp, const char *s1, const char *s2, SIZE_T n) {<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+INTERCEPTOR(int, strncasecmp, const char *s1, const char *s2, SIZE_T size) {<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
void *ctx;<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
- COMMON_INTERCEPTOR_ENTER(ctx, strncasecmp, s1, s2, n);<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+ COMMON_INTERCEPTOR_ENTER(ctx, strncasecmp, s1, s2, size);<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
unsigned char c1 = 0, c2 = 0;<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
uptr i;<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
- for (i = 0; i < n; i++) {<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+ for (i = 0; i < size; i++) {<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
c1 = (unsigned char)s1[i];<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
c2 = (unsigned char)s2[i];<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
if (CharCaseCmp(c1, c2) != 0 || c1 == '\0') break;<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
}<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
- COMMON_INTERCEPTOR_READ_RANGE(ctx, s1, Min(i + 1, n));<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
- COMMON_INTERCEPTOR_READ_RANGE(ctx, s2, Min(i + 1, n));<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+ uptr i1 = i;<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+ uptr i2 = i;<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+ if (common_flags()->strict_string_checks) {<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+ for (; i1 < size && s1[i1]; i1++) {}<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+ for (; i2 < size && s2[i2]; i2++) {}<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+ }<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+ COMMON_INTERCEPTOR_READ_RANGE((ctx), (s1), Min(i1 + 1, size));<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+ COMMON_INTERCEPTOR_READ_RANGE((ctx), (s2), Min(i2 + 1, size));<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
int result = CharCaseCmp(c1, c2);<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
CALL_WEAK_INTERCEPTOR_HOOK(__sanitizer_weak_hook_strncasecmp, GET_CALLER_PC(),<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
- s1, s2, n, result);<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+ s1, s2, size, result);<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
return result;<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
}<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
Modified: compiler-rt/trunk/test/asan/TestCases/strncmp_strict.c<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/strncmp_strict.c?rev=286708&r1=286707&r2=286708&view=diff" rel="noreferrer" class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/strncmp_strict.c?rev=286708&r1=286707&r2=286708&view=diff</a><br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
==============================================================================<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
--- compiler-rt/trunk/test/asan/TestCases/strncmp_strict.c (original)<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+++ compiler-rt/trunk/test/asan/TestCases/strncmp_strict.c Fri Nov 11 22:32:31 2016<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
@@ -1,26 +1,81 @@<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
// Test strict_string_checks option in strncmp function<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
-// RUN: %clang_asan %s -o %t && %run %t 2>&1<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
-// RUN: %env_asan_opts=strict_string_checks=false %run %t 2>&1<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
-// RUN: %env_asan_opts=strict_string_checks=true not %run %t 2>&1 | FileCheck %s<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+// RUN: %clang_asan %s -o %t<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+// RUN: %env_asan_opts=strict_string_checks=false %run %t a 2>&1<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+// RUN: %env_asan_opts=strict_string_checks=true %run %t a 2>&1<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+// RUN: not %run %t b 2>&1 | FileCheck %s<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+// RUN: not %run %t c 2>&1 | FileCheck %s<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+// RUN: not %run %t d 2>&1 | FileCheck %s<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+// RUN: not %run %t e 2>&1 | FileCheck %s<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+// RUN: not %run %t f 2>&1 | FileCheck %s<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+// RUN: not %run %t g 2>&1 | FileCheck %s<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+// RUN: %env_asan_opts=strict_string_checks=false %run %t h 2>&1<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+// RUN: %env_asan_opts=strict_string_checks=true not %run %t h 2>&1 | FileCheck %s<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+// RUN: %env_asan_opts=strict_string_checks=false %run %t i 2>&1<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+// RUN: %env_asan_opts=strict_string_checks=true not %run %t i 2>&1 | FileCheck %s<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+// RUN: %env_asan_opts=strict_string_checks=false %run %t A 2>&1<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+// RUN: %env_asan_opts=strict_string_checks=true %run %t A 2>&1<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+// RUN: not %run %t B 2>&1 | FileCheck %s<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+// RUN: not %run %t C 2>&1 | FileCheck %s<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+// RUN: not %run %t D 2>&1 | FileCheck %s<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+// RUN: not %run %t E 2>&1 | FileCheck %s<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+// RUN: not %run %t F 2>&1 | FileCheck %s<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+// RUN: not %run %t G 2>&1 | FileCheck %s<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+// RUN: %env_asan_opts=strict_string_checks=false %run %t H 2>&1<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+// RUN: %env_asan_opts=strict_string_checks=true not %run %t H 2>&1 | FileCheck %s<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+// RUN: %env_asan_opts=strict_string_checks=false %run %t I 2>&1<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+// RUN: %env_asan_opts=strict_string_checks=true not %run %t I 2>&1 | FileCheck %s<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
#include <assert.h><br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
#include <stdlib.h><br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+#include <stdio.h><br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
#include <string.h><br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+#include <ctype.h><br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
int main(int argc, char **argv) {<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
- size_t size = 100;<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+ assert(argc >= 2);<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+ const size_t size = 100;<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
char fill = 'o';<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
- char *s1 = (char*)malloc(size);<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+ char s1[size];<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+ char s2[size];<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
memset(s1, fill, size);<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
- char *s2 = (char*)malloc(size);<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
memset(s2, fill, size);<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
- s1[size - 1] = 'z';<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
- s2[size - 1] = 'x';<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
- int r = strncmp(s1, s2, size + 1);<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
- // CHECK: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}}<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
- // CHECK: READ of size 101<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
- assert(r == 1);<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
- free(s1);<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
- free(s2);<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+ int (*cmp_fn)(const char *, const char *, size_t);<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+ cmp_fn = islower(argv[1][0]) ? &strncmp : &strncasecmp;<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+ switch(tolower(argv[1][0])) {<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+ case 'a':<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+ s1[size - 1] = 'z';<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+ s2[size - 1] = 'x';<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+ for (int i = 0; i <= size; ++i)<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+ assert((cmp_fn(s1, s2, i) == 0) == (i < size));<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+ s1[size - 1] = '\0';<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+ s2[size - 1] = '\0';<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+ assert(cmp_fn(s1, s2, 2*size) == 0);<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+ break;<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+ case 'b':<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+ return cmp_fn(s1-1, s2, 1);<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+ case 'c':<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+ return cmp_fn(s1, s2-1, 1);<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+ case 'd':<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+ return cmp_fn(s1+size, s2, 1);<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+ case 'e':<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+ return cmp_fn(s1, s2+size, 1);<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+ case 'f':<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+ return cmp_fn(s1+1, s2, size);<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+ case 'g':<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+ return cmp_fn(s1, s2+1, size);<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+ case 'h':<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+ s1[size - 1] = '\0';<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+ assert(cmp_fn(s1, s2, 2*size) != 0);<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+ break;<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+ case 'i':<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+ s2[size - 1] = '\0';<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+ assert(cmp_fn(s1, s2, 2*size) != 0);<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+ break;<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+ // CHECK: {{.*}}ERROR: AddressSanitizer: stack-buffer-{{ov|und}}erflow on address<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
+ }<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
return 0;<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
}<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
_______________________________________________<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
llvm-commits mailing list<br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
<a href="mailto:llvm-commits@lists.llvm.org" class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg" target="_blank">llvm-commits@lists.llvm.org</a><br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg">
</blockquote></div><br class="m_-3365828223990859221m_7581341900603118733gmail_msg gmail_msg"></div>
</blockquote></div>
</div></div></blockquote></div><br class="gmail_msg"></div>
</blockquote></div>