blob: 4b78c2058341968c3daa2531900c1b60ef82f530 [file] [log] [blame]
Ted Kremenekd55522f2010-02-25 00:20:35 +00001//= UnixAPIChecker.h - Checks preconditions for various Unix APIs --*- 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 UnixAPIChecker, which is an assortment of checks on calls
11// to various, widely used UNIX/Posix functions.
12//
13//===----------------------------------------------------------------------===//
14
Argyrios Kyrtzidisa6d04d52011-02-15 07:42:33 +000015#include "ClangSACheckers.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000016#include "clang/Basic/TargetInfo.h"
17#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
Argyrios Kyrtzidis6a5674f2011-03-01 01:16:21 +000018#include "clang/StaticAnalyzer/Core/Checker.h"
Argyrios Kyrtzidis507ff532011-02-17 21:39:17 +000019#include "clang/StaticAnalyzer/Core/CheckerManager.h"
Argyrios Kyrtzidisdff865d2011-02-23 01:05:36 +000020#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
Ted Kremenek26984fb2010-04-09 20:26:58 +000021#include "llvm/ADT/Optional.h"
Benjamin Kramer3307c5082012-02-04 12:31:12 +000022#include "llvm/ADT/STLExtras.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000023#include "llvm/ADT/SmallString.h"
Benjamin Kramerc0483222010-03-27 21:19:47 +000024#include "llvm/ADT/StringSwitch.h"
Benjamin Kramer444a1302012-12-01 17:12:56 +000025#include "llvm/Support/raw_ostream.h"
Ted Kremenekd55522f2010-02-25 00:20:35 +000026#include <fcntl.h>
27
28using namespace clang;
Ted Kremenek98857c92010-12-23 07:20:52 +000029using namespace ento;
Ted Kremenekd55522f2010-02-25 00:20:35 +000030
31namespace {
Argyrios Kyrtzidis6a5674f2011-03-01 01:16:21 +000032class UnixAPIChecker : public Checker< check::PreStmt<CallExpr> > {
Ahmed Charlesb8984322014-03-07 20:03:18 +000033 mutable std::unique_ptr<BugType> BT_open, BT_pthreadOnce, BT_mallocZero;
Argyrios Kyrtzidisdff865d2011-02-23 01:05:36 +000034 mutable Optional<uint64_t> Val_O_CREAT;
Ted Kremenek212182d2010-04-08 22:15:34 +000035
36public:
Argyrios Kyrtzidisdff865d2011-02-23 01:05:36 +000037 void checkPreStmt(const CallExpr *CE, CheckerContext &C) const;
Jordy Rosef3dd00a2011-07-15 06:28:59 +000038
39 void CheckOpen(CheckerContext &C, const CallExpr *CE) const;
40 void CheckPthreadOnce(CheckerContext &C, const CallExpr *CE) const;
Ted Kremenek134a83a2012-01-03 23:43:13 +000041 void CheckCallocZero(CheckerContext &C, const CallExpr *CE) const;
Jordy Rosef3dd00a2011-07-15 06:28:59 +000042 void CheckMallocZero(CheckerContext &C, const CallExpr *CE) const;
Ted Kremenek134a83a2012-01-03 23:43:13 +000043 void CheckReallocZero(CheckerContext &C, const CallExpr *CE) const;
Jordan Rose9e068aa2012-10-30 01:37:16 +000044 void CheckReallocfZero(CheckerContext &C, const CallExpr *CE) const;
Ted Kremenek940e00f2012-01-11 08:13:21 +000045 void CheckAllocaZero(CheckerContext &C, const CallExpr *CE) const;
46 void CheckVallocZero(CheckerContext &C, const CallExpr *CE) const;
Jordy Rosef3dd00a2011-07-15 06:28:59 +000047
48 typedef void (UnixAPIChecker::*SubChecker)(CheckerContext &,
49 const CallExpr *) const;
Ted Kremenek134a83a2012-01-03 23:43:13 +000050private:
51 bool ReportZeroByteAllocation(CheckerContext &C,
Ted Kremenek49b1e382012-01-26 21:29:00 +000052 ProgramStateRef falseState,
Ted Kremenek134a83a2012-01-03 23:43:13 +000053 const Expr *arg,
54 const char *fn_name) const;
Ted Kremenek940e00f2012-01-11 08:13:21 +000055 void BasicAllocationCheck(CheckerContext &C,
56 const CallExpr *CE,
57 const unsigned numArgs,
58 const unsigned sizeArg,
59 const char *fn) const;
Ahmed Charlesb8984322014-03-07 20:03:18 +000060 void LazyInitialize(std::unique_ptr<BugType> &BT, const char *name) const {
Alexander Kornienko4aca9b12014-02-11 21:49:21 +000061 if (BT)
62 return;
63 BT.reset(new BugType(this, name, categories::UnixAPI));
64 }
Jordan Rosecd4db5c2014-08-20 16:58:03 +000065 void ReportOpenBug(CheckerContext &C,
66 ProgramStateRef State,
67 const char *Msg,
68 SourceRange SR) const;
Ted Kremenekd55522f2010-02-25 00:20:35 +000069};
70} //end anonymous namespace
71
Ted Kremenekd55522f2010-02-25 00:20:35 +000072//===----------------------------------------------------------------------===//
Ted Kremenekd55522f2010-02-25 00:20:35 +000073// "open" (man 2 open)
74//===----------------------------------------------------------------------===//
75
Jordan Rosecd4db5c2014-08-20 16:58:03 +000076void UnixAPIChecker::ReportOpenBug(CheckerContext &C,
77 ProgramStateRef State,
78 const char *Msg,
79 SourceRange SR) const {
Devin Coughline39bd402015-09-16 22:03:05 +000080 ExplodedNode *N = C.generateErrorNode(State);
Jordan Rosecd4db5c2014-08-20 16:58:03 +000081 if (!N)
82 return;
83
84 LazyInitialize(BT_open, "Improper use of 'open'");
85
Aaron Ballman8d3a7a52015-06-23 13:15:32 +000086 auto Report = llvm::make_unique<BugReport>(*BT_open, Msg, N);
Jordan Rosecd4db5c2014-08-20 16:58:03 +000087 Report->addRange(SR);
Aaron Ballman8d3a7a52015-06-23 13:15:32 +000088 C.emitReport(std::move(Report));
Jordan Rosecd4db5c2014-08-20 16:58:03 +000089}
90
Jordy Rosef3dd00a2011-07-15 06:28:59 +000091void UnixAPIChecker::CheckOpen(CheckerContext &C, const CallExpr *CE) const {
Jordan Rosecd4db5c2014-08-20 16:58:03 +000092 ProgramStateRef state = C.getState();
93
94 if (CE->getNumArgs() < 2) {
95 // The frontend should issue a warning for this case, so this is a sanity
96 // check.
97 return;
Jordan Roseba129af2014-08-20 16:58:09 +000098 } else if (CE->getNumArgs() == 3) {
99 const Expr *Arg = CE->getArg(2);
100 QualType QT = Arg->getType();
101 if (!QT->isIntegerType()) {
102 ReportOpenBug(C, state,
103 "Third argument to 'open' is not an integer",
104 Arg->getSourceRange());
105 return;
106 }
Jordan Rosecd4db5c2014-08-20 16:58:03 +0000107 } else if (CE->getNumArgs() > 3) {
108 ReportOpenBug(C, state,
109 "Call to 'open' with more than three arguments",
110 CE->getArg(3)->getSourceRange());
111 return;
112 }
113
Ted Kremenek212182d2010-04-08 22:15:34 +0000114 // The definition of O_CREAT is platform specific. We need a better way
115 // of querying this information from the checking environment.
Jordy Rosef3dd00a2011-07-15 06:28:59 +0000116 if (!Val_O_CREAT.hasValue()) {
Ted Kremenek3a0678e2015-09-08 03:50:52 +0000117 if (C.getASTContext().getTargetInfo().getTriple().getVendor()
Douglas Gregore8bbc122011-09-02 00:18:52 +0000118 == llvm::Triple::Apple)
Jordy Rosef3dd00a2011-07-15 06:28:59 +0000119 Val_O_CREAT = 0x0200;
Ted Kremenek212182d2010-04-08 22:15:34 +0000120 else {
121 // FIXME: We need a more general way of getting the O_CREAT value.
122 // We could possibly grovel through the preprocessor state, but
Argyrios Kyrtzidis1696f502010-12-22 18:53:44 +0000123 // that would require passing the Preprocessor object to the ExprEngine.
Jordan Rose6b33c6f2014-03-26 17:05:46 +0000124 // See also: MallocChecker.cpp / M_ZERO.
Ted Kremenek212182d2010-04-08 22:15:34 +0000125 return;
126 }
127 }
128
Ted Kremenekd55522f2010-02-25 00:20:35 +0000129 // Now check if oflags has O_CREAT set.
130 const Expr *oflagsEx = CE->getArg(1);
Ted Kremenek632e3b72012-01-06 22:09:28 +0000131 const SVal V = state->getSVal(oflagsEx, C.getLocationContext());
David Blaikie2fdacbc2013-02-20 05:52:05 +0000132 if (!V.getAs<NonLoc>()) {
Ted Kremenekd55522f2010-02-25 00:20:35 +0000133 // The case where 'V' can be a location can only be due to a bad header,
134 // so in this case bail out.
135 return;
136 }
David Blaikie2fdacbc2013-02-20 05:52:05 +0000137 NonLoc oflags = V.castAs<NonLoc>();
138 NonLoc ocreateFlag = C.getSValBuilder()
139 .makeIntVal(Val_O_CREAT.getValue(), oflagsEx->getType()).castAs<NonLoc>();
Ted Kremenekdc891422010-12-01 21:57:22 +0000140 SVal maskedFlagsUC = C.getSValBuilder().evalBinOpNN(state, BO_And,
Ted Kremenek9d0bb1e2010-12-01 21:28:31 +0000141 oflags, ocreateFlag,
142 oflagsEx->getType());
Ted Kremenekd55522f2010-02-25 00:20:35 +0000143 if (maskedFlagsUC.isUnknownOrUndef())
144 return;
David Blaikie2fdacbc2013-02-20 05:52:05 +0000145 DefinedSVal maskedFlags = maskedFlagsUC.castAs<DefinedSVal>();
Ted Kremenekd55522f2010-02-25 00:20:35 +0000146
147 // Check if maskedFlags is non-zero.
Ted Kremenek49b1e382012-01-26 21:29:00 +0000148 ProgramStateRef trueState, falseState;
Benjamin Kramer867ea1d2014-03-02 13:01:17 +0000149 std::tie(trueState, falseState) = state->assume(maskedFlags);
Ted Kremenekd55522f2010-02-25 00:20:35 +0000150
151 // Only emit an error if the value of 'maskedFlags' is properly
152 // constrained;
153 if (!(trueState && !falseState))
154 return;
155
156 if (CE->getNumArgs() < 3) {
Jordan Rosecd4db5c2014-08-20 16:58:03 +0000157 ReportOpenBug(C, trueState,
158 "Call to 'open' requires a third argument when "
159 "the 'O_CREAT' flag is set",
160 oflagsEx->getSourceRange());
Ted Kremenekd55522f2010-02-25 00:20:35 +0000161 }
162}
163
164//===----------------------------------------------------------------------===//
Ted Kremenekea4a5ab2010-04-08 19:53:31 +0000165// pthread_once
166//===----------------------------------------------------------------------===//
167
Jordy Rosef3dd00a2011-07-15 06:28:59 +0000168void UnixAPIChecker::CheckPthreadOnce(CheckerContext &C,
169 const CallExpr *CE) const {
Ted Kremenekea4a5ab2010-04-08 19:53:31 +0000170
171 // This is similar to 'CheckDispatchOnce' in the MacOSXAPIChecker.
172 // They can possibly be refactored.
173
Ted Kremenekea4a5ab2010-04-08 19:53:31 +0000174 if (CE->getNumArgs() < 1)
175 return;
176
177 // Check if the first argument is stack allocated. If so, issue a warning
178 // because that's likely to be bad news.
Ted Kremenek49b1e382012-01-26 21:29:00 +0000179 ProgramStateRef state = C.getState();
Ted Kremenek632e3b72012-01-06 22:09:28 +0000180 const MemRegion *R =
181 state->getSVal(CE->getArg(0), C.getLocationContext()).getAsRegion();
Ted Kremenekea4a5ab2010-04-08 19:53:31 +0000182 if (!R || !isa<StackSpaceRegion>(R->getMemorySpace()))
183 return;
184
Devin Coughline39bd402015-09-16 22:03:05 +0000185 ExplodedNode *N = C.generateErrorNode(state);
Ted Kremenekea4a5ab2010-04-08 19:53:31 +0000186 if (!N)
187 return;
188
Dylan Noblesmith2c1dd272012-02-05 02:13:05 +0000189 SmallString<256> S;
Ted Kremenekea4a5ab2010-04-08 19:53:31 +0000190 llvm::raw_svector_ostream os(S);
191 os << "Call to 'pthread_once' uses";
192 if (const VarRegion *VR = dyn_cast<VarRegion>(R))
193 os << " the local variable '" << VR->getDecl()->getName() << '\'';
194 else
195 os << " stack allocated memory";
196 os << " for the \"control\" value. Using such transient memory for "
197 "the control value is potentially dangerous.";
198 if (isa<VarRegion>(R) && isa<StackLocalsSpaceRegion>(R->getMemorySpace()))
199 os << " Perhaps you intended to declare the variable as 'static'?";
200
Jordy Rosef3dd00a2011-07-15 06:28:59 +0000201 LazyInitialize(BT_pthreadOnce, "Improper use of 'pthread_once'");
202
Aaron Ballman8d3a7a52015-06-23 13:15:32 +0000203 auto report = llvm::make_unique<BugReport>(*BT_pthreadOnce, os.str(), N);
Ted Kremenekea4a5ab2010-04-08 19:53:31 +0000204 report->addRange(CE->getArg(0)->getSourceRange());
Aaron Ballman8d3a7a52015-06-23 13:15:32 +0000205 C.emitReport(std::move(report));
Ted Kremenekea4a5ab2010-04-08 19:53:31 +0000206}
207
208//===----------------------------------------------------------------------===//
Jordan Rose9e068aa2012-10-30 01:37:16 +0000209// "calloc", "malloc", "realloc", "reallocf", "alloca" and "valloc"
210// with allocation size 0
Ted Kremenek0c27bcf2010-11-16 18:47:04 +0000211//===----------------------------------------------------------------------===//
Ted Kremenek940e00f2012-01-11 08:13:21 +0000212// FIXME: Eventually these should be rolled into the MallocChecker, but right now
213// they're more basic and valuable for widespread use.
Ted Kremenek0c27bcf2010-11-16 18:47:04 +0000214
Ted Kremenek134a83a2012-01-03 23:43:13 +0000215// Returns true if we try to do a zero byte allocation, false otherwise.
216// Fills in trueState and falseState.
Ted Kremenek49b1e382012-01-26 21:29:00 +0000217static bool IsZeroByteAllocation(ProgramStateRef state,
Ted Kremenek134a83a2012-01-03 23:43:13 +0000218 const SVal argVal,
Ted Kremenek49b1e382012-01-26 21:29:00 +0000219 ProgramStateRef *trueState,
220 ProgramStateRef *falseState) {
Benjamin Kramer867ea1d2014-03-02 13:01:17 +0000221 std::tie(*trueState, *falseState) =
David Blaikie2fdacbc2013-02-20 05:52:05 +0000222 state->assume(argVal.castAs<DefinedSVal>());
Ted Kremenek3a0678e2015-09-08 03:50:52 +0000223
Ted Kremenek134a83a2012-01-03 23:43:13 +0000224 return (*falseState && !*trueState);
225}
226
227// Generates an error report, indicating that the function whose name is given
228// will perform a zero byte allocation.
Alp Tokerf6a24ce2013-12-05 16:25:25 +0000229// Returns false if an error occurred, true otherwise.
Ted Kremenek134a83a2012-01-03 23:43:13 +0000230bool UnixAPIChecker::ReportZeroByteAllocation(CheckerContext &C,
Ted Kremenek49b1e382012-01-26 21:29:00 +0000231 ProgramStateRef falseState,
Ted Kremenek134a83a2012-01-03 23:43:13 +0000232 const Expr *arg,
233 const char *fn_name) const {
Devin Coughline39bd402015-09-16 22:03:05 +0000234 ExplodedNode *N = C.generateErrorNode(falseState);
Ted Kremenek134a83a2012-01-03 23:43:13 +0000235 if (!N)
236 return false;
237
Ted Kremenek940e00f2012-01-11 08:13:21 +0000238 LazyInitialize(BT_mallocZero,
Alexander Kornienko4aca9b12014-02-11 21:49:21 +0000239 "Undefined allocation of 0 bytes (CERT MEM04-C; CWE-131)");
Ted Kremenek134a83a2012-01-03 23:43:13 +0000240
Dylan Noblesmith2c1dd272012-02-05 02:13:05 +0000241 SmallString<256> S;
Ted Kremenek3a0678e2015-09-08 03:50:52 +0000242 llvm::raw_svector_ostream os(S);
Ted Kremenek134a83a2012-01-03 23:43:13 +0000243 os << "Call to '" << fn_name << "' has an allocation size of 0 bytes";
Aaron Ballman8d3a7a52015-06-23 13:15:32 +0000244 auto report = llvm::make_unique<BugReport>(*BT_mallocZero, os.str(), N);
Ted Kremenek134a83a2012-01-03 23:43:13 +0000245
246 report->addRange(arg->getSourceRange());
Jordan Rosea0f7d352012-08-28 00:50:51 +0000247 bugreporter::trackNullOrUndefValue(N, arg, *report);
Aaron Ballman8d3a7a52015-06-23 13:15:32 +0000248 C.emitReport(std::move(report));
Ted Kremenek134a83a2012-01-03 23:43:13 +0000249
250 return true;
251}
252
Ted Kremenek940e00f2012-01-11 08:13:21 +0000253// Does a basic check for 0-sized allocations suitable for most of the below
254// functions (modulo "calloc")
255void UnixAPIChecker::BasicAllocationCheck(CheckerContext &C,
256 const CallExpr *CE,
257 const unsigned numArgs,
258 const unsigned sizeArg,
259 const char *fn) const {
260 // Sanity check for the correct number of arguments
261 if (CE->getNumArgs() != numArgs)
262 return;
263
264 // Check if the allocation size is 0.
Ted Kremenek49b1e382012-01-26 21:29:00 +0000265 ProgramStateRef state = C.getState();
Craig Topper0dbb7832014-05-27 02:45:47 +0000266 ProgramStateRef trueState = nullptr, falseState = nullptr;
Ted Kremenek940e00f2012-01-11 08:13:21 +0000267 const Expr *arg = CE->getArg(sizeArg);
268 SVal argVal = state->getSVal(arg, C.getLocationContext());
269
270 if (argVal.isUnknownOrUndef())
271 return;
272
273 // Is the value perfectly constrained to zero?
274 if (IsZeroByteAllocation(state, argVal, &trueState, &falseState)) {
Ted Kremenek3a0678e2015-09-08 03:50:52 +0000275 (void) ReportZeroByteAllocation(C, falseState, arg, fn);
Ted Kremenek940e00f2012-01-11 08:13:21 +0000276 return;
277 }
Sylvestre Ledru830885c2012-07-23 08:59:39 +0000278 // Assume the value is non-zero going forward.
Ted Kremenek940e00f2012-01-11 08:13:21 +0000279 assert(trueState);
280 if (trueState != state)
Ted Kremenek3a0678e2015-09-08 03:50:52 +0000281 C.addTransition(trueState);
Ted Kremenek940e00f2012-01-11 08:13:21 +0000282}
283
Ted Kremenek134a83a2012-01-03 23:43:13 +0000284void UnixAPIChecker::CheckCallocZero(CheckerContext &C,
285 const CallExpr *CE) const {
286 unsigned int nArgs = CE->getNumArgs();
287 if (nArgs != 2)
288 return;
289
Ted Kremenek49b1e382012-01-26 21:29:00 +0000290 ProgramStateRef state = C.getState();
Craig Topper0dbb7832014-05-27 02:45:47 +0000291 ProgramStateRef trueState = nullptr, falseState = nullptr;
Ted Kremenek134a83a2012-01-03 23:43:13 +0000292
293 unsigned int i;
294 for (i = 0; i < nArgs; i++) {
295 const Expr *arg = CE->getArg(i);
Ted Kremenek632e3b72012-01-06 22:09:28 +0000296 SVal argVal = state->getSVal(arg, C.getLocationContext());
Ted Kremenek134a83a2012-01-03 23:43:13 +0000297 if (argVal.isUnknownOrUndef()) {
298 if (i == 0)
299 continue;
300 else
301 return;
302 }
303
304 if (IsZeroByteAllocation(state, argVal, &trueState, &falseState)) {
305 if (ReportZeroByteAllocation(C, falseState, arg, "calloc"))
306 return;
307 else if (i == 0)
308 continue;
309 else
310 return;
311 }
312 }
313
Sylvestre Ledru830885c2012-07-23 08:59:39 +0000314 // Assume the value is non-zero going forward.
Ted Kremenek134a83a2012-01-03 23:43:13 +0000315 assert(trueState);
316 if (trueState != state)
317 C.addTransition(trueState);
318}
319
Jordy Rosef3dd00a2011-07-15 06:28:59 +0000320void UnixAPIChecker::CheckMallocZero(CheckerContext &C,
321 const CallExpr *CE) const {
Ted Kremenek940e00f2012-01-11 08:13:21 +0000322 BasicAllocationCheck(C, CE, 1, 0, "malloc");
Ted Kremenek134a83a2012-01-03 23:43:13 +0000323}
324
325void UnixAPIChecker::CheckReallocZero(CheckerContext &C,
326 const CallExpr *CE) const {
Ted Kremenek940e00f2012-01-11 08:13:21 +0000327 BasicAllocationCheck(C, CE, 2, 1, "realloc");
Ted Kremenek0c27bcf2010-11-16 18:47:04 +0000328}
Ted Kremenek940e00f2012-01-11 08:13:21 +0000329
Jordan Rose9e068aa2012-10-30 01:37:16 +0000330void UnixAPIChecker::CheckReallocfZero(CheckerContext &C,
331 const CallExpr *CE) const {
332 BasicAllocationCheck(C, CE, 2, 1, "reallocf");
333}
334
Ted Kremenek940e00f2012-01-11 08:13:21 +0000335void UnixAPIChecker::CheckAllocaZero(CheckerContext &C,
336 const CallExpr *CE) const {
337 BasicAllocationCheck(C, CE, 1, 0, "alloca");
338}
339
340void UnixAPIChecker::CheckVallocZero(CheckerContext &C,
341 const CallExpr *CE) const {
342 BasicAllocationCheck(C, CE, 1, 0, "valloc");
343}
344
345
Ted Kremenek0c27bcf2010-11-16 18:47:04 +0000346//===----------------------------------------------------------------------===//
Ted Kremenekd55522f2010-02-25 00:20:35 +0000347// Central dispatch function.
348//===----------------------------------------------------------------------===//
349
Ted Kremenek940e00f2012-01-11 08:13:21 +0000350void UnixAPIChecker::checkPreStmt(const CallExpr *CE,
351 CheckerContext &C) const {
Jordan Rose6cd16c52012-07-10 23:13:01 +0000352 const FunctionDecl *FD = C.getCalleeDecl(CE);
353 if (!FD || FD->getKind() != Decl::Function)
354 return;
355
356 StringRef FName = C.getCalleeName(FD);
Anna Zaksc6aa5312011-12-01 05:57:37 +0000357 if (FName.empty())
Ted Kremenekd55522f2010-02-25 00:20:35 +0000358 return;
359
Jordy Rosef3dd00a2011-07-15 06:28:59 +0000360 SubChecker SC =
Anna Zaksc6aa5312011-12-01 05:57:37 +0000361 llvm::StringSwitch<SubChecker>(FName)
Jordy Rosef3dd00a2011-07-15 06:28:59 +0000362 .Case("open", &UnixAPIChecker::CheckOpen)
363 .Case("pthread_once", &UnixAPIChecker::CheckPthreadOnce)
Ted Kremenek134a83a2012-01-03 23:43:13 +0000364 .Case("calloc", &UnixAPIChecker::CheckCallocZero)
Jordy Rosef3dd00a2011-07-15 06:28:59 +0000365 .Case("malloc", &UnixAPIChecker::CheckMallocZero)
Ted Kremenek134a83a2012-01-03 23:43:13 +0000366 .Case("realloc", &UnixAPIChecker::CheckReallocZero)
Jordan Rose9e068aa2012-10-30 01:37:16 +0000367 .Case("reallocf", &UnixAPIChecker::CheckReallocfZero)
Ted Kremenek940e00f2012-01-11 08:13:21 +0000368 .Cases("alloca", "__builtin_alloca", &UnixAPIChecker::CheckAllocaZero)
369 .Case("valloc", &UnixAPIChecker::CheckVallocZero)
Craig Topper0dbb7832014-05-27 02:45:47 +0000370 .Default(nullptr);
Ted Kremenekd55522f2010-02-25 00:20:35 +0000371
Jordy Rosef3dd00a2011-07-15 06:28:59 +0000372 if (SC)
373 (this->*SC)(C, CE);
Ted Kremenekd55522f2010-02-25 00:20:35 +0000374}
Argyrios Kyrtzidisdff865d2011-02-23 01:05:36 +0000375
376//===----------------------------------------------------------------------===//
377// Registration.
378//===----------------------------------------------------------------------===//
379
380void ento::registerUnixAPIChecker(CheckerManager &mgr) {
381 mgr.registerChecker<UnixAPIChecker>();
382}