From: Reka Kovacs Date: Thu, 19 Jul 2018 17:43:09 +0000 (+0000) Subject: [analyzer] Fix memory sanitizer error in MallocChecker. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=77c4e2380a572bfab344ca1bfc7b59beb9cf8fff;p=clang [analyzer] Fix memory sanitizer error in MallocChecker. StringRef's data() returns a string that may be non-null-terminated. Switch to using StringRefs from const char pointers in visitor notes to avoid problems. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@337474 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/StaticAnalyzer/Checkers/MallocChecker.cpp b/lib/StaticAnalyzer/Checkers/MallocChecker.cpp index 5dcd9b3863..be3289a395 100644 --- a/lib/StaticAnalyzer/Checkers/MallocChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/MallocChecker.cpp @@ -2899,7 +2899,7 @@ std::shared_ptr MallocChecker::MallocBugVisitor::VisitNode( // (__attribute__((cleanup))). // Find out if this is an interesting point and what is the kind. - const char *Msg = nullptr; + StringRef Msg; StackHintGeneratorForSymbol *StackHint = nullptr; SmallString<256> Buf; llvm::raw_svector_ostream OS(Buf); @@ -2933,7 +2933,7 @@ std::shared_ptr MallocChecker::MallocBugVisitor::VisitNode( } OS << "'"; } - Msg = OS.str().data(); + Msg = OS.str(); break; } case AF_None: @@ -3004,7 +3004,7 @@ std::shared_ptr MallocChecker::MallocBugVisitor::VisitNode( } } - if (!Msg) + if (Msg.empty()) return nullptr; assert(StackHint);