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

Gabor Marton via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 26 07:41:37 PDT 2022


martong accepted this revision.
martong added a reviewer: whisperity.
martong added a subscriber: whisperity.
martong added a comment.
This revision is now accepted and ready to land.

We had a discussion about this with @dkrupp . We think that the `p = realloc(p, var)` construct in itself is an error-prone **style** of using `realloc`. This style does not necessarily give birth to erroneous code (see the error-free escaping example in `foo` above from @steakhal). However, the form `p = realloc(p, var)` is an indication that the programmer might missed the non-trivial error handling case, and chances are high. Thus, one should use the `p2 = realloc(p1, var)` form as a best practice. So, this looks good to me, but please consider this a weak approve and wait for someone else's approve who has more confidence in clang-tidy (@whisperity could you please take a look?).


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