[PATCH] D133119: [clang-tidy] Add checker 'bugprone-suspicious-realloc-usage'.

Balázs Benics via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 1 08:58:15 PDT 2022


steakhal added a comment.

Consider adding a test case demonstrating if the checker recognizes and suppresses the check if there are multiple variables referring to the memory being reallocated.
If the check does not handle that case, we should probably state this limitation explicitly. And marking the corresponding test case with a FIXME.

I was thinking about something like this:

  void escape(void *);
  void foo(void *p) {
    void *q = p;
    p = realloc(p, 10); // no-warning
    escape(q);
  }
  void bar(void *p) {
    p = realloc(p, 10); // warn: ...
    void *q = p;
    escape(q);
  }

The `MallocOverflowCheck` does something similar. It uses `isBeforeInTranslationUnit()`.



================
Comment at: clang-tools-extra/clang-tidy/bugprone/SuspiciousReallocUsageCheck.cpp:20-21
+namespace {
+class IsSamePtrExpr : public clang::StmtVisitor<IsSamePtrExpr, bool> /*,
+                         public clang::DeclVisitor<IsSamePtrExpr, bool>*/
+{
----------------
Commented code?


================
Comment at: clang-tools-extra/clang-tidy/bugprone/SuspiciousReallocUsageCheck.cpp:23
+{
+  /// The other expression to compare with.
+  /// This variable is used to pass the data from a \c check function to any of
----------------
against


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D133119/new/

https://reviews.llvm.org/D133119



More information about the cfe-commits mailing list