summaryrefslogtreecommitdiffstats
path: root/docs
diff options
context:
space:
mode:
authorAdam Balogh <adam.balogh@ericsson.com>2017-11-23 12:26:28 +0000
committerAdam Balogh <adam.balogh@ericsson.com>2017-11-23 12:26:28 +0000
commit31bdad483ab4a8af1b87ae217c0672da17da2b67 (patch)
treef884ae7d0a3cb133c7581747b9ac62cc1c76b40c /docs
parent432924ce077aaaf21a40eb60a57b34626372daaf (diff)
[clang-tidy] Misplaced Operator in Strlen in Alloc
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. git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@318906 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'docs')
-rw-r--r--docs/ReleaseNotes.rst9
-rw-r--r--docs/clang-tidy/checks/list.rst1
2 files changed, 10 insertions, 0 deletions
diff --git a/docs/ReleaseNotes.rst b/docs/ReleaseNotes.rst
index 2ec26ee0..02377878 100644
--- a/docs/ReleaseNotes.rst
+++ b/docs/ReleaseNotes.rst
@@ -85,6 +85,15 @@ Improvements to clang-tidy
not intended to be subclassed. Includes a list of classes from Foundation
and UIKit which are documented as not supporting subclassing.
+- New `bugprone-misplaced-operator-in-strlen-in-alloc
+ <http://clang.llvm.org/extra/clang-tidy/checks/bugprone-misplaced-operator-in-strlen-in-alloc.html>`_ check
+
+ Finds cases where ``1`` is added to the string in the argument to
+ ``strlen()``, ``strnlen()``, ``strnlen_s()``, ``wcslen()``, ``wcsnlen()``, and
+ ``wcsnlen_s()`` instead of the result and the value is used as an argument to
+ a memory allocation function (``malloc()``, ``calloc()``, ``realloc()``,
+ ``alloca()``).
+
- Renamed checks to use correct term "implicit conversion" instead of "implicit
cast" and modified messages and option names accordingly:
diff --git a/docs/clang-tidy/checks/list.rst b/docs/clang-tidy/checks/list.rst
index 4fab7509..8b5957af 100644
--- a/docs/clang-tidy/checks/list.rst
+++ b/docs/clang-tidy/checks/list.rst
@@ -19,6 +19,7 @@ Clang-Tidy Checks
boost-use-to-string
bugprone-copy-constructor-init
bugprone-integer-division
+ bugprone-misplaced-operator-in-strlen-in-alloc
bugprone-suspicious-memset-usage
bugprone-undefined-memory-manipulation
cert-dcl03-c (redirects to misc-static-assert) <cert-dcl03-c>