aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Kramer <benny.kra@googlemail.com>2009-11-14 12:08:24 +0000
committerBenjamin Kramer <benny.kra@googlemail.com>2009-11-14 12:08:24 +0000
commitd02e232c43b979758810794de24d3f5cde40fe93 (patch)
tree32a20b050ba1a7c26828bde07df0f8d8bd7355eb
parent4fdba99ccce46d577ea1bcd5081843ef95ff5c11 (diff)
Change *BugReport constructors to take StringRefs.
- Eliminates many calls to std::string.c_str() - Fixes an invalid read in ReturnStackAddressChecker due to an unsafe call to StringRef.data() which doesn't guarantee null-termination. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@88779 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Analysis/PathSensitive/BugReporter.h16
-rw-r--r--lib/Analysis/ArrayBoundChecker.cpp2
-rw-r--r--lib/Analysis/BadCallChecker.cpp2
-rw-r--r--lib/Analysis/CallGraph.cpp2
-rw-r--r--lib/Analysis/CastToStructChecker.cpp3
-rw-r--r--lib/Analysis/DereferenceChecker.cpp4
-rw-r--r--lib/Analysis/DivZeroChecker.cpp2
-rw-r--r--lib/Analysis/FixedAddressChecker.cpp3
-rw-r--r--lib/Analysis/MallocChecker.cpp4
-rw-r--r--lib/Analysis/PointerArithChecker.cpp3
-rw-r--r--lib/Analysis/PointerSubChecker.cpp3
-rw-r--r--lib/Analysis/ReturnPointerRangeChecker.cpp2
-rw-r--r--lib/Analysis/ReturnStackAddressChecker.cpp2
-rw-r--r--lib/Analysis/ReturnUndefChecker.cpp2
-rw-r--r--lib/Analysis/UndefinedArgChecker.cpp3
-rw-r--r--lib/Analysis/UndefinedArraySubscriptChecker.cpp3
-rw-r--r--lib/Analysis/UndefinedAssignmentChecker.cpp2
-rw-r--r--lib/Analysis/VLASizeChecker.cpp4
18 files changed, 28 insertions, 34 deletions
diff --git a/include/clang/Analysis/PathSensitive/BugReporter.h b/include/clang/Analysis/PathSensitive/BugReporter.h
index 914118cb43..f4297350ec 100644
--- a/include/clang/Analysis/PathSensitive/BugReporter.h
+++ b/include/clang/Analysis/PathSensitive/BugReporter.h
@@ -81,10 +81,10 @@ public:
getOriginalNode(const ExplodedNode* N) = 0;
};
- BugReport(BugType& bt, const char* desc, const ExplodedNode *n)
+ BugReport(BugType& bt, llvm::StringRef desc, const ExplodedNode *n)
: BT(bt), Description(desc), EndNode(n) {}
- BugReport(BugType& bt, const char* shortDesc, const char* desc,
+ BugReport(BugType& bt, llvm::StringRef shortDesc, llvm::StringRef desc,
const ExplodedNode *n)
: BT(bt), ShortDescription(shortDesc), Description(desc), EndNode(n) {}
@@ -193,11 +193,11 @@ public:
class RangedBugReport : public BugReport {
std::vector<SourceRange> Ranges;
public:
- RangedBugReport(BugType& D, const char* description, ExplodedNode *n)
+ RangedBugReport(BugType& D, llvm::StringRef description, ExplodedNode *n)
: BugReport(D, description, n) {}
- RangedBugReport(BugType& D, const char *shortDescription,
- const char *description, ExplodedNode *n)
+ RangedBugReport(BugType& D, llvm::StringRef shortDescription,
+ llvm::StringRef description, ExplodedNode *n)
: BugReport(D, shortDescription, description, n) {}
~RangedBugReport();
@@ -229,11 +229,11 @@ private:
Creators creators;
public:
- EnhancedBugReport(BugType& D, const char* description, ExplodedNode *n)
+ EnhancedBugReport(BugType& D, llvm::StringRef description, ExplodedNode *n)
: RangedBugReport(D, description, n) {}
- EnhancedBugReport(BugType& D, const char *shortDescription,
- const char *description, ExplodedNode *n)
+ EnhancedBugReport(BugType& D, llvm::StringRef shortDescription,
+ llvm::StringRef description, ExplodedNode *n)
: RangedBugReport(D, shortDescription, description, n) {}
~EnhancedBugReport() {}
diff --git a/lib/Analysis/ArrayBoundChecker.cpp b/lib/Analysis/ArrayBoundChecker.cpp
index 34a5631edd..549a22bec1 100644
--- a/lib/Analysis/ArrayBoundChecker.cpp
+++ b/lib/Analysis/ArrayBoundChecker.cpp
@@ -77,7 +77,7 @@ void ArrayBoundChecker::VisitLocation(CheckerContext &C, const Stmt *S, SVal l){
// Generate a report for this bug.
RangedBugReport *report =
- new RangedBugReport(*BT, BT->getDescription().c_str(), N);
+ new RangedBugReport(*BT, BT->getDescription(), N);
report->addRange(S->getSourceRange());
diff --git a/lib/Analysis/BadCallChecker.cpp b/lib/Analysis/BadCallChecker.cpp
index 4175e8d141..7a7ea188ba 100644
--- a/lib/Analysis/BadCallChecker.cpp
+++ b/lib/Analysis/BadCallChecker.cpp
@@ -46,7 +46,7 @@ void BadCallChecker::PreVisitCallExpr(CheckerContext &C, const CallExpr *CE) {
"Called function pointer is a null or undefined pointer value");
EnhancedBugReport *R =
- new EnhancedBugReport(*BT, BT->getDescription().c_str(), N);
+ new EnhancedBugReport(*BT, BT->getDescription(), N);
R->addVisitorCreator(bugreporter::registerTrackNullOrUndefValue,
bugreporter::GetCalleeExpr(N));
diff --git a/lib/Analysis/CallGraph.cpp b/lib/Analysis/CallGraph.cpp
index 17dc0685f8..06e3317691 100644
--- a/lib/Analysis/CallGraph.cpp
+++ b/lib/Analysis/CallGraph.cpp
@@ -117,7 +117,7 @@ void CallGraph::print(llvm::raw_ostream &os) {
<< " calls:\n";
for (CallGraphNode::iterator CI = I->second->begin(),
CE = I->second->end(); CI != CE; ++CI) {
- os << " " << CI->second->getName().c_str();
+ os << " " << CI->second->getName();
}
os << '\n';
}
diff --git a/lib/Analysis/CastToStructChecker.cpp b/lib/Analysis/CastToStructChecker.cpp
index bda8ff47bf..ccd4a3333e 100644
--- a/lib/Analysis/CastToStructChecker.cpp
+++ b/lib/Analysis/CastToStructChecker.cpp
@@ -65,8 +65,7 @@ void CastToStructChecker::PreVisitCastExpr(CheckerContext &C,
"Casting a non-structure type to a structure type "
"and accessing a field can lead to memory access "
"errors or data corruption.");
- RangedBugReport *R = new RangedBugReport(*BT,BT->getDescription().c_str(),
- N);
+ RangedBugReport *R = new RangedBugReport(*BT,BT->getDescription(), N);
R->addRange(CE->getSourceRange());
C.EmitReport(R);
}
diff --git a/lib/Analysis/DereferenceChecker.cpp b/lib/Analysis/DereferenceChecker.cpp
index 6fdad5d2a4..c3aa8f3a28 100644
--- a/lib/Analysis/DereferenceChecker.cpp
+++ b/lib/Analysis/DereferenceChecker.cpp
@@ -62,7 +62,7 @@ void DereferenceChecker::VisitLocation(CheckerContext &C, const Stmt *S,
BT_undef = new BuiltinBug("Dereference of undefined pointer value");
EnhancedBugReport *report =
- new EnhancedBugReport(*BT_undef, BT_undef->getDescription().c_str(), N);
+ new EnhancedBugReport(*BT_undef, BT_undef->getDescription(), N);
report->addVisitorCreator(bugreporter::registerTrackNullOrUndefValue,
bugreporter::GetDerefExpr(N));
C.EmitReport(report);
@@ -93,7 +93,7 @@ void DereferenceChecker::VisitLocation(CheckerContext &C, const Stmt *S,
"Dereference of null pointer");
EnhancedBugReport *report =
- new EnhancedBugReport(*BT_null, BT_null->getDescription().c_str(), N);
+ new EnhancedBugReport(*BT_null, BT_null->getDescription(), N);
report->addVisitorCreator(bugreporter::registerTrackNullOrUndefValue,
bugreporter::GetDerefExpr(N));
diff --git a/lib/Analysis/DivZeroChecker.cpp b/lib/Analysis/DivZeroChecker.cpp
index 5f949fdc39..a8630f1008 100644
--- a/lib/Analysis/DivZeroChecker.cpp
+++ b/lib/Analysis/DivZeroChecker.cpp
@@ -68,7 +68,7 @@ void DivZeroChecker::PreVisitBinaryOperator(CheckerContext &C,
BT = new BuiltinBug("Division by zero");
EnhancedBugReport *R =
- new EnhancedBugReport(*BT, BT->getDescription().c_str(), N);
+ new EnhancedBugReport(*BT, BT->getDescription(), N);
R->addVisitorCreator(bugreporter::registerTrackNullOrUndefValue,
bugreporter::GetDenomExpr(N));
diff --git a/lib/Analysis/FixedAddressChecker.cpp b/lib/Analysis/FixedAddressChecker.cpp
index e30e3d0ce1..80096dcb70 100644
--- a/lib/Analysis/FixedAddressChecker.cpp
+++ b/lib/Analysis/FixedAddressChecker.cpp
@@ -59,8 +59,7 @@ void FixedAddressChecker::PreVisitBinaryOperator(CheckerContext &C,
"Using a fixed address is not portable because that "
"address will probably not be valid in all "
"environments or platforms.");
- RangedBugReport *R = new RangedBugReport(*BT, BT->getDescription().c_str(),
- N);
+ RangedBugReport *R = new RangedBugReport(*BT, BT->getDescription(), N);
R->addRange(B->getRHS()->getSourceRange());
C.EmitReport(R);
}
diff --git a/lib/Analysis/MallocChecker.cpp b/lib/Analysis/MallocChecker.cpp
index 6655194d5e..6129358cf7 100644
--- a/lib/Analysis/MallocChecker.cpp
+++ b/lib/Analysis/MallocChecker.cpp
@@ -123,7 +123,7 @@ void MallocChecker::FreeMem(CheckerContext &C, const CallExpr *CE) {
"Try to free a memory block that has been released");
// FIXME: should find where it's freed last time.
BugReport *R = new BugReport(*BT_DoubleFree,
- BT_DoubleFree->getDescription().c_str(), N);
+ BT_DoubleFree->getDescription(), N);
C.EmitReport(R);
}
return;
@@ -152,7 +152,7 @@ void MallocChecker::EvalDeadSymbols(CheckerContext &C, const Stmt *S,
"Allocated memory never released. Potential memory leak.");
// FIXME: where it is allocated.
BugReport *R = new BugReport(*BT_Leak,
- BT_Leak->getDescription().c_str(), N);
+ BT_Leak->getDescription(), N);
C.EmitReport(R);
}
}
diff --git a/lib/Analysis/PointerArithChecker.cpp b/lib/Analysis/PointerArithChecker.cpp
index 5f5badb3d2..93823484e1 100644
--- a/lib/Analysis/PointerArithChecker.cpp
+++ b/lib/Analysis/PointerArithChecker.cpp
@@ -59,8 +59,7 @@ void PointerArithChecker::PreVisitBinaryOperator(CheckerContext &C,
"Pointer arithmetic done on non-array variables "
"means reliance on memory layout, which is "
"dangerous.");
- RangedBugReport *R = new RangedBugReport(*BT,BT->getDescription().c_str(),
- N);
+ RangedBugReport *R = new RangedBugReport(*BT, BT->getDescription(), N);
R->addRange(B->getSourceRange());
C.EmitReport(R);
}
diff --git a/lib/Analysis/PointerSubChecker.cpp b/lib/Analysis/PointerSubChecker.cpp
index 20279c67b3..4c7906f4be 100644
--- a/lib/Analysis/PointerSubChecker.cpp
+++ b/lib/Analysis/PointerSubChecker.cpp
@@ -66,8 +66,7 @@ void PointerSubChecker::PreVisitBinaryOperator(CheckerContext &C,
BT = new BuiltinBug("Pointer subtraction",
"Subtraction of two pointers that do not point to "
"the same memory chunk may cause incorrect result.");
- RangedBugReport *R = new RangedBugReport(*BT, BT->getDescription().c_str(),
- N);
+ RangedBugReport *R = new RangedBugReport(*BT, BT->getDescription(), N);
R->addRange(B->getSourceRange());
C.EmitReport(R);
}
diff --git a/lib/Analysis/ReturnPointerRangeChecker.cpp b/lib/Analysis/ReturnPointerRangeChecker.cpp
index f007d0e0d1..44887b2625 100644
--- a/lib/Analysis/ReturnPointerRangeChecker.cpp
+++ b/lib/Analysis/ReturnPointerRangeChecker.cpp
@@ -88,7 +88,7 @@ void ReturnPointerRangeChecker::PreVisitReturnStmt(CheckerContext &C,
// Generate a report for this bug.
RangedBugReport *report =
- new RangedBugReport(*BT, BT->getDescription().c_str(), N);
+ new RangedBugReport(*BT, BT->getDescription(), N);
report->addRange(RetE->getSourceRange());
diff --git a/lib/Analysis/ReturnStackAddressChecker.cpp b/lib/Analysis/ReturnStackAddressChecker.cpp
index 9f22b3c48e..e4be8712d0 100644
--- a/lib/Analysis/ReturnStackAddressChecker.cpp
+++ b/lib/Analysis/ReturnStackAddressChecker.cpp
@@ -88,7 +88,7 @@ void ReturnStackAddressChecker::PreVisitReturnStmt(CheckerContext &C,
<< R->getString() << "' returned.";
}
- RangedBugReport *report = new RangedBugReport(*BT, os.str().data(), N);
+ RangedBugReport *report = new RangedBugReport(*BT, os.str(), N);
report->addRange(RS->getSourceRange());
if (range.isValid())
report->addRange(range);
diff --git a/lib/Analysis/ReturnUndefChecker.cpp b/lib/Analysis/ReturnUndefChecker.cpp
index adde3f5d25..796c7608c8 100644
--- a/lib/Analysis/ReturnUndefChecker.cpp
+++ b/lib/Analysis/ReturnUndefChecker.cpp
@@ -60,7 +60,7 @@ void ReturnUndefChecker::PreVisitReturnStmt(CheckerContext &C,
"Undefined or garbage value returned to caller");
EnhancedBugReport *report =
- new EnhancedBugReport(*BT, BT->getDescription().c_str(), N);
+ new EnhancedBugReport(*BT, BT->getDescription(), N);
report->addVisitorCreator(bugreporter::registerTrackNullOrUndefValue, RetE);
diff --git a/lib/Analysis/UndefinedArgChecker.cpp b/lib/Analysis/UndefinedArgChecker.cpp
index 43b4847cc4..923a7e1bed 100644
--- a/lib/Analysis/UndefinedArgChecker.cpp
+++ b/lib/Analysis/UndefinedArgChecker.cpp
@@ -46,8 +46,7 @@ void UndefinedArgChecker::PreVisitCallExpr(CheckerContext &C,
BT = new BuiltinBug("Pass-by-value argument in function call is "
"undefined");
// Generate a report for this bug.
- EnhancedBugReport *R = new EnhancedBugReport(*BT, BT->getName().c_str(),
- N);
+ EnhancedBugReport *R = new EnhancedBugReport(*BT, BT->getName(), N);
R->addRange((*I)->getSourceRange());
R->addVisitorCreator(bugreporter::registerTrackNullOrUndefValue, *I);
C.EmitReport(R);
diff --git a/lib/Analysis/UndefinedArraySubscriptChecker.cpp b/lib/Analysis/UndefinedArraySubscriptChecker.cpp
index 47d615dbbd..887c7755fe 100644
--- a/lib/Analysis/UndefinedArraySubscriptChecker.cpp
+++ b/lib/Analysis/UndefinedArraySubscriptChecker.cpp
@@ -46,8 +46,7 @@ UndefinedArraySubscriptChecker::PreVisitArraySubscriptExpr(CheckerContext &C,
BT = new BuiltinBug("Array subscript is undefined");
// Generate a report for this bug.
- EnhancedBugReport *R = new EnhancedBugReport(*BT, BT->getName().c_str(),
- N);
+ EnhancedBugReport *R = new EnhancedBugReport(*BT, BT->getName(), N);
R->addRange(A->getIdx()->getSourceRange());
R->addVisitorCreator(bugreporter::registerTrackNullOrUndefValue,
A->getIdx());
diff --git a/lib/Analysis/UndefinedAssignmentChecker.cpp b/lib/Analysis/UndefinedAssignmentChecker.cpp
index 26f9ee30d4..b8062f3595 100644
--- a/lib/Analysis/UndefinedAssignmentChecker.cpp
+++ b/lib/Analysis/UndefinedAssignmentChecker.cpp
@@ -39,7 +39,7 @@ void UndefinedAssignmentChecker::PreVisitBind(CheckerContext &C,
BT = new BuiltinBug("Assigned value is garbage or undefined");
// Generate a report for this bug.
- EnhancedBugReport *R = new EnhancedBugReport(*BT, BT->getName().c_str(), N);
+ EnhancedBugReport *R = new EnhancedBugReport(*BT, BT->getName(), N);
if (AssignE) {
const Expr *ex = 0;
diff --git a/lib/Analysis/VLASizeChecker.cpp b/lib/Analysis/VLASizeChecker.cpp
index 5cb700ed67..799a73e293 100644
--- a/lib/Analysis/VLASizeChecker.cpp
+++ b/lib/Analysis/VLASizeChecker.cpp
@@ -64,7 +64,7 @@ void VLASizeChecker::PreVisitDeclStmt(CheckerContext &C, const DeclStmt *DS) {
"garbage value as its size");
EnhancedBugReport *report =
- new EnhancedBugReport(*BT_undef, BT_undef->getName().c_str(), N);
+ new EnhancedBugReport(*BT_undef, BT_undef->getName(), N);
report->addRange(SE->getSourceRange());
report->addVisitorCreator(bugreporter::registerTrackNullOrUndefValue, SE);
C.EmitReport(report);
@@ -84,7 +84,7 @@ void VLASizeChecker::PreVisitDeclStmt(CheckerContext &C, const DeclStmt *DS) {
"size");
EnhancedBugReport *report =
- new EnhancedBugReport(*BT_zero, BT_zero->getName().c_str(), N);
+ new EnhancedBugReport(*BT_zero, BT_zero->getName(), N);
report->addRange(SE->getSourceRange());
report->addVisitorCreator(bugreporter::registerTrackNullOrUndefValue, SE);
C.EmitReport(report);