blob: 33bb5158d2b9ca32821088717293cb1be3deb511 [file] [log] [blame]
Zhongxing Xu4f64e5f2009-11-03 05:48:04 +00001//===--- BadCallChecker.h - Bad call checker --------------------*- C++ -*--==//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This defines BadCallChecker, a builtin check in GRExprEngine that performs
11// checks for bad callee at call sites.
12//
13//===----------------------------------------------------------------------===//
14
15#include "clang/Analysis/PathSensitive/Checkers/BadCallChecker.h"
16#include "clang/Analysis/PathSensitive/BugReporter.h"
17
18using namespace clang;
19
20void *BadCallChecker::getTag() {
21 static int x = 0;
22 return &x;
23}
24
25void BadCallChecker::PreVisitCallExpr(CheckerContext &C, const CallExpr *CE) {
26 const Expr *Callee = CE->getCallee()->IgnoreParens();
27 SVal L = C.getState()->getSVal(Callee);
28
29 if (L.isUndef() || isa<loc::ConcreteInt>(L)) {
30 if (ExplodedNode *N = C.GenerateNode(CE, true)) {
31 if (!BT)
32 BT = new BuiltinBug(0, "Invalid function call",
33 "Called function pointer is a null or undefined pointer value");
34
35 EnhancedBugReport *R =
36 new EnhancedBugReport(*BT, BT->getDescription().c_str(), N);
37
38 R->addVisitorCreator(bugreporter::registerTrackNullOrUndefValue,
39 bugreporter::GetCalleeExpr(N));
40
41 C.EmitReport(R);
42 }
43 }
44}