[PATCH] D39121: [clang-tidy] Misplaced Operator in Strlen in Alloc

Balogh, Ádám via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 20 05:49:51 PDT 2017


baloghadamsoftware created this revision.
Herald added subscribers: mgorny, srhines.

A possible error is to write ``malloc(strlen(s+1))`` instead of ``malloc(strlen(s)+1)``. Unfortunately the former is also valid syntactically, but allocates less memory by two bytes (if ``s`` is at least one character long, undefined behavior otherwise) which may result in overflow cases. This check detects such cases and also suggests the fix for them.


https://reviews.llvm.org/D39121

Files:
  clang-tidy/misc/CMakeLists.txt
  clang-tidy/misc/MiscTidyModule.cpp
  clang-tidy/misc/MisplacedOperatorInStrlenInAllocCheck.cpp
  clang-tidy/misc/MisplacedOperatorInStrlenInAllocCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/misc-misplaced-operator-in-strlen-in-alloc.rst
  test/clang-tidy/misc-misplaced-operator-in-strlen-in-alloc.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D39121.119650.patch
Type: text/x-patch
Size: 11445 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20171020/bfc38e18/attachment.bin>


More information about the cfe-commits mailing list