forked from OSchip/llvm-project
Hoist diagnostic generation in ReturnStackAddressChecker into a separate method. No functionality change.
llvm-svn: 95037
This commit is contained in:
parent
9afa973203
commit
0059c491c1
|
@ -30,6 +30,8 @@ public:
|
||||||
ReturnStackAddressChecker() : BT(0) {}
|
ReturnStackAddressChecker() : BT(0) {}
|
||||||
static void *getTag();
|
static void *getTag();
|
||||||
void PreVisitReturnStmt(CheckerContext &C, const ReturnStmt *RS);
|
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;
|
static int x = 0; return &x;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ReturnStackAddressChecker::PreVisitReturnStmt(CheckerContext &C,
|
void ReturnStackAddressChecker::EmitStackError(CheckerContext &C,
|
||||||
const ReturnStmt *RS) {
|
const MemRegion *R,
|
||||||
|
const Expr *RetE) {
|
||||||
const Expr *RetE = RS->getRetValue();
|
|
||||||
if (!RetE)
|
|
||||||
return;
|
|
||||||
|
|
||||||
SVal V = C.getState()->getSVal(RetE);
|
|
||||||
const MemRegion *R = V.getAsRegion();
|
|
||||||
|
|
||||||
if (!R || !R->hasStackStorage())
|
|
||||||
return;
|
|
||||||
|
|
||||||
ExplodedNode *N = C.GenerateSink();
|
ExplodedNode *N = C.GenerateSink();
|
||||||
|
|
||||||
if (!N)
|
if (!N)
|
||||||
|
@ -63,7 +55,7 @@ void ReturnStackAddressChecker::PreVisitReturnStmt(CheckerContext &C,
|
||||||
BT = new BuiltinBug("Return of address to stack-allocated memory");
|
BT = new BuiltinBug("Return of address to stack-allocated memory");
|
||||||
|
|
||||||
// Generate a report for this bug.
|
// Generate a report for this bug.
|
||||||
llvm::SmallString<100> buf;
|
llvm::SmallString<512> buf;
|
||||||
llvm::raw_svector_ostream os(buf);
|
llvm::raw_svector_ostream os(buf);
|
||||||
SourceRange range;
|
SourceRange range;
|
||||||
|
|
||||||
|
@ -112,3 +104,22 @@ void ReturnStackAddressChecker::PreVisitReturnStmt(CheckerContext &C,
|
||||||
|
|
||||||
C.EmitReport(report);
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue