From 1be519876d7e5c5c6bc4bbad34237a5e0b222765 Mon Sep 17 00:00:00 2001 From: Alexey Samsonov Date: Mon, 2 Mar 2015 18:55:46 +0000 Subject: [PATCH] [Sanitizer] Fix StripPathPrefix function and improve test case. llvm-svn: 230986 --- compiler-rt/lib/sanitizer_common/sanitizer_common.cc | 12 ++++++------ compiler-rt/test/asan/TestCases/strip_path_prefix.c | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common.cc b/compiler-rt/lib/sanitizer_common/sanitizer_common.cc index 030264b..350252e 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_common.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_common.cc @@ -207,12 +207,12 @@ const char *StripPathPrefix(const char *filepath, const char *strip_path_prefix) { if (filepath == 0) return 0; if (strip_path_prefix == 0) return filepath; - const char *pos = internal_strstr(filepath, strip_path_prefix); - if (pos == 0) return filepath; - pos += internal_strlen(strip_path_prefix); - if (pos[0] == '.' && pos[1] == '/') - pos += 2; - return pos; + const char *res = filepath; + if (const char *pos = internal_strstr(filepath, strip_path_prefix)) + res = pos + internal_strlen(strip_path_prefix); + if (res[0] == '.' && res[1] == '/') + res += 2; + return res; } const char *StripModuleName(const char *module) { diff --git a/compiler-rt/test/asan/TestCases/strip_path_prefix.c b/compiler-rt/test/asan/TestCases/strip_path_prefix.c index 4556e90..c441eac 100644 --- a/compiler-rt/test/asan/TestCases/strip_path_prefix.c +++ b/compiler-rt/test/asan/TestCases/strip_path_prefix.c @@ -1,5 +1,5 @@ // RUN: %clang_asan -O2 %s -o %t -// RUN: env ASAN_OPTIONS="strip_path_prefix='/'" not %run %t 2>&1 | FileCheck %s +// RUN: env ASAN_OPTIONS="strip_path_prefix='%S/'" not %run %t 2>&1 | FileCheck %s #include int main() { @@ -8,5 +8,5 @@ int main() { return x[5]; // Check that paths in error report don't start with slash. // CHECK: heap-use-after-free - // CHECK-NOT: #0 0x{{.*}} ({{[/].*}}) + // CHECK: #0 0x{{.*}} in main strip_path_prefix.c:[[@LINE-3]] } -- 2.7.4