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



_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to