[PATCH] D26167: [Clang-tidy] check for malloc, realloc and free calls

Alexander Kornienko via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 12 08:58:55 PST 2016


alexfh requested changes to this revision.
alexfh added inline comments.
This revision now requires changes to proceed.


================
Comment at: clang-tidy/cppcoreguidelines/NoMallocCheck.cpp:54
+
+void NoMallocCheck::handleAquisition(const CallExpr *AquisitionCall) {
+  diag(AquisitionCall->getLocStart(),
----------------
The handle.* methods now just add more bulk and bring no benefit. With a single statement in each function they might as well be inlined and the `check`method would be still quite compact:
```
CallExpr Call = nullptr;
StringRef Recommendation;
if ((Call = Result.Nodes.getNodeAs<CallExpr>("aquisition")))
  Recommendation = "consider a container or smartpointer";
else if ((Call = ...))
  ...;

assert(Call && "Unhandled binding in the matcher);

diag(Call->getLocStart(),
     "do not allocate memory manually; %0")
  << Recommendation
  << SourceRange(...);
```


================
Comment at: clang-tidy/cppcoreguidelines/NoMallocCheck.cpp:56
+  diag(AquisitionCall->getLocStart(),
+       "do not allocate memory manually; consider a container or smartpointer")
+      << SourceRange{AquisitionCall->getLocStart(),
----------------
"smart pointer" is two words.


================
Comment at: clang-tidy/cppcoreguidelines/NoMallocCheck.cpp:57
+       "do not allocate memory manually; consider a container or smartpointer")
+      << SourceRange{AquisitionCall->getLocStart(),
+                     AquisitionCall->getLocEnd()};
----------------
Please use parentheses instead of curly braces for constructor calls (`SourceRange(x, y)`), it's more common in LLVM code.


Repository:
  rL LLVM

https://reviews.llvm.org/D26167





More information about the cfe-commits mailing list