Hoist diagnostic generation in ReturnStackAddressChecker into a separate method. No functionality change.

llvm-svn: 95037
This commit is contained in:
Ted Kremenek 2010-02-02 00:13:41 +00:00
parent 9afa973203
commit 0059c491c1
1 changed files with 69 additions and 58 deletions

View File

@ -30,6 +30,8 @@ public:
ReturnStackAddressChecker() : BT(0) {}
static void *getTag();
void PreVisitReturnStmt(CheckerContext &C, const ReturnStmt *RS);
private:
void EmitStackError(CheckerContext &C, const MemRegion *R, const Expr *RetE);
};
}
@ -41,19 +43,9 @@ void *ReturnStackAddressChecker::getTag() {
static int x = 0; return &x;
}
void ReturnStackAddressChecker::PreVisitReturnStmt(CheckerContext &C,
const ReturnStmt *RS) {
const Expr *RetE = RS->getRetValue();
if (!RetE)
return;
SVal V = C.getState()->getSVal(RetE);
const MemRegion *R = V.getAsRegion();
if (!R || !R->hasStackStorage())
return;
void ReturnStackAddressChecker::EmitStackError(CheckerContext &C,
const MemRegion *R,
const Expr *RetE) {
ExplodedNode *N = C.GenerateSink();
if (!N)
@ -63,7 +55,7 @@ void ReturnStackAddressChecker::PreVisitReturnStmt(CheckerContext &C,
BT = new BuiltinBug("Return of address to stack-allocated memory");
// Generate a report for this bug.
llvm::SmallString<100> buf;
llvm::SmallString<512> buf;
llvm::raw_svector_ostream os(buf);
SourceRange range;
@ -112,3 +104,22 @@ void ReturnStackAddressChecker::PreVisitReturnStmt(CheckerContext &C,
C.EmitReport(report);
}
void ReturnStackAddressChecker::PreVisitReturnStmt(CheckerContext &C,
const ReturnStmt *RS) {
const Expr *RetE = RS->getRetValue();
if (!RetE)
return;
SVal V = C.getState()->getSVal(RetE);
const MemRegion *R = V.getAsRegion();
if (!R || !R->hasStackStorage())
return;
if (R->hasStackStorage()) {
EmitStackError(C, R, RetE);
return;
}
}