diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc --- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc @@ -7974,7 +7974,7 @@ if (pattern) COMMON_INTERCEPTOR_READ_RANGE(ctx, pattern, internal_strlen(pattern) + 1); int res = REAL(regcomp)(preg, pattern, cflags); - if (!res) + if (preg) COMMON_INTERCEPTOR_WRITE_RANGE(ctx, preg, struct_regex_sz); return res; } diff --git a/compiler-rt/test/sanitizer_common/TestCases/Posix/regex.cpp b/compiler-rt/test/sanitizer_common/TestCases/Posix/regex.cpp --- a/compiler-rt/test/sanitizer_common/TestCases/Posix/regex.cpp +++ b/compiler-rt/test/sanitizer_common/TestCases/Posix/regex.cpp @@ -42,23 +42,30 @@ int main(void) { printf("regex\n"); - regex_t regex; - int rv = regcomp(®ex, "[[:upper:]]\\([[:upper:]]\\)", 0); - assert(!rv); + { + regex_t regex; + int rv = regcomp(®ex, "[[:upper:]]\\([[:upper:]]\\)", 0); + assert(!rv); - test_matched(®ex, "abc"); - test_matched(®ex, "ABC"); + test_matched(®ex, "abc"); + test_matched(®ex, "ABC"); - test_print_matches(®ex, "ABC"); + test_print_matches(®ex, "ABC"); - regfree(®ex); + regfree(®ex); + } - rv = regcomp(®ex, "[[:upp:]]", 0); - assert(rv); + { + regex_t regex; + int rv = regcomp(®ex, "[[:upp:]]", 0); + assert(rv); - char errbuf[1024]; - regerror(rv, ®ex, errbuf, sizeof errbuf); - printf("error: %s\n", errbuf); + char errbuf[1024]; + regerror(rv, ®ex, errbuf, sizeof errbuf); + printf("error: %s\n", errbuf); + + regfree(®ex); + } // CHECK: regex // CHECK: abc: not-matched