[analyzer] Fix memory sanitizer error in MallocChecker.
authorReka Kovacs <rekanikolett@gmail.com>
Thu, 19 Jul 2018 17:43:09 +0000 (17:43 +0000)
committerReka Kovacs <rekanikolett@gmail.com>
Thu, 19 Jul 2018 17:43:09 +0000 (17:43 +0000)
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.

llvm-svn: 337474

clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp

index 5dcd9b3..be3289a 100644 (file)
@@ -2899,7 +2899,7 @@ std::shared_ptr<PathDiagnosticPiece> 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<PathDiagnosticPiece> MallocChecker::MallocBugVisitor::VisitNode(
             }
             OS << "'";
           }
-          Msg = OS.str().data();
+          Msg = OS.str();
           break;
         }
         case AF_None:
@@ -3004,7 +3004,7 @@ std::shared_ptr<PathDiagnosticPiece> MallocChecker::MallocBugVisitor::VisitNode(
     }
   }
 
-  if (!Msg)
+  if (Msg.empty())
     return nullptr;
   assert(StackHint);