[PATCH] D32346: [clang-tidy] New readability check for strlen argument
Jonas Toth via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Apr 25 03:36:25 PDT 2017
JonasToth added inline comments.
================
Comment at: docs/clang-tidy/checks/readability-strlen-argument.rst:8
+
+In the example code below the developer probably wanted to make room for an extra char in the allocation but misplaced the addition.
+
----------------
when the intend was to allocate one more char, he would need to do `strlen(s) + 1`, why is it changed to subtraction then?
================
Comment at: docs/clang-tidy/checks/readability-strlen-argument.rst:20
+ char *p = new char[(strlen(s) - 1)]
+ strcpy(p, s);
+
----------------
isnt that an overflow?
an example:
`strlen(s) == 10` -> `p` will be 9 characters long, since its substracted with `1`.
the copy operation will then copy the content of `s` into `p`, therefore copying 10 characters into a buffer of length 9.
as i understand it `strcpy(p, s + 1)` would be correct with the sizes.
Repository:
rL LLVM
https://reviews.llvm.org/D32346
More information about the cfe-commits
mailing list