[clang-tidy] Misplaced Operator in Strlen in Alloc
authorAdam Balogh <adam.balogh@ericsson.com>
Thu, 23 Nov 2017 12:33:12 +0000 (12:33 +0000)
committerAdam Balogh <adam.balogh@ericsson.com>
Thu, 23 Nov 2017 12:33:12 +0000 (12:33 +0000)
commit4c488975daf72e5ffd3b57971950d9e563d65074
tree14a270a50dd7c41085b59f7a3b5d5d8337359b6d
parent2079defd8d13d6eebe7d902d08733afbc8198faf
[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.

Fix for r318906, forgot to add new files.

llvm-svn: 318907
clang-tools-extra/clang-tidy/bugprone/MisplacedOperatorInStrlenInAllocCheck.cpp [new file with mode: 0644]
clang-tools-extra/clang-tidy/bugprone/MisplacedOperatorInStrlenInAllocCheck.h [new file with mode: 0644]
clang-tools-extra/docs/clang-tidy/checks/bugprone-misplaced-operator-in-strlen-in-alloc.rst [new file with mode: 0644]
clang-tools-extra/test/clang-tidy/bugprone-misplaced-operator-in-strlen-in-alloc.c [new file with mode: 0644]
clang-tools-extra/test/clang-tidy/bugprone-misplaced-operator-in-strlen-in-alloc.cpp [new file with mode: 0644]