From: Ted Kremenek Date: Fri, 6 Mar 2009 07:53:30 +0000 (+0000) Subject: Fix regression: initialize 'size' for PathDiagnostic to 0. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4850451c8e93789c099d907dd469898ea9561ecb;p=clang Fix regression: initialize 'size' for PathDiagnostic to 0. Add some assertions along the way... git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66265 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Analysis/PathDiagnostic.h b/include/clang/Analysis/PathDiagnostic.h index 702879c3dd..a387910860 100644 --- a/include/clang/Analysis/PathDiagnostic.h +++ b/include/clang/Analysis/PathDiagnostic.h @@ -37,8 +37,12 @@ private: const DisplayHint Hint; std::vector ranges; -public: + // Do not implement: + PathDiagnosticPiece(); + PathDiagnosticPiece(const PathDiagnosticPiece &P); + PathDiagnosticPiece& operator=(const PathDiagnosticPiece &P); +public: PathDiagnosticPiece(FullSourceLoc pos, const std::string& s, Kind k = Event, DisplayHint hint = Above); @@ -98,10 +102,10 @@ class PathDiagnostic { std::string Desc; std::string Category; std::vector OtherDesc; - + public: - PathDiagnostic() : Size(0) {} - + PathDiagnostic(); + PathDiagnostic(const char* bugtype, const char* desc, const char* category); PathDiagnostic(const std::string& bugtype, const std::string& desc, diff --git a/lib/Analysis/PathDiagnostic.cpp b/lib/Analysis/PathDiagnostic.cpp index c078b6d0f2..468b6c89f2 100644 --- a/lib/Analysis/PathDiagnostic.cpp +++ b/lib/Analysis/PathDiagnostic.cpp @@ -36,12 +36,20 @@ static inline size_t GetNumCharsToLastNonPeriod(const std::string &s) { PathDiagnosticPiece::PathDiagnosticPiece(FullSourceLoc pos, const std::string& s, Kind k, DisplayHint hint) - : Pos(pos), str(s, 0, GetNumCharsToLastNonPeriod(s)), kind(k), Hint(hint) {} + : Pos(pos), str(s, 0, GetNumCharsToLastNonPeriod(s)), kind(k), Hint(hint) { + assert(Pos.isValid() && + "PathDiagnosticPiece's must have a valid location."); +} PathDiagnosticPiece::PathDiagnosticPiece(FullSourceLoc pos, const char* s, Kind k, DisplayHint hint) - : Pos(pos), str(s, GetNumCharsToLastNonPeriod(s)), kind(k), Hint(hint) {} + : Pos(pos), str(s, GetNumCharsToLastNonPeriod(s)), kind(k), Hint(hint) { + assert(Pos.isValid() && + "PathDiagnosticPiece's must have a valid location."); +} + +PathDiagnostic::PathDiagnostic() : Size(0) {} PathDiagnostic::~PathDiagnostic() { for (iterator I = begin(), E = end(); I != E; ++I) delete &*I; @@ -50,14 +58,16 @@ PathDiagnostic::~PathDiagnostic() { PathDiagnostic::PathDiagnostic(const char* bugtype, const char* desc, const char* category) - : BugType(bugtype, GetNumCharsToLastNonPeriod(bugtype)), + : Size(0), + BugType(bugtype, GetNumCharsToLastNonPeriod(bugtype)), Desc(desc, GetNumCharsToLastNonPeriod(desc)), Category(category, GetNumCharsToLastNonPeriod(category)) {} PathDiagnostic::PathDiagnostic(const std::string& bugtype, const std::string& desc, const std::string& category) - : BugType(bugtype, 0, GetNumCharsToLastNonPeriod(bugtype)), + : Size(0), + BugType(bugtype, 0, GetNumCharsToLastNonPeriod(bugtype)), Desc(desc, 0, GetNumCharsToLastNonPeriod(desc)), Category(category, 0, GetNumCharsToLastNonPeriod(category)) {}