[PATCH] D39121: [clang-tidy] Misplaced Operator in Strlen in Alloc
Balogh, Ádám via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 31 07:36:33 PDT 2017
baloghadamsoftware added a comment.
Can you give me please an example where `malloc(strlen(s+1))` is intentional. It allocates `2` byte less than needed to store `s`. If it is really the goal (e.g. `s` has a `2` character prefix which we do not want to copy) then the correct solution is to use `malloc(strlen(s+2)+1)` instead of putting `s+1` into extra parentheses. So I think that we are overcomplicating things here. I would simply delete the suggestion about the extra parentheses from the error message and leave them only in the documentation, at least until no real example comes to my mind where taking the length of `s+1` and not adding `+1` is the fully correct solution. (Please note the `malloc(strlen(s+1)+1)` is already ignored.
https://reviews.llvm.org/D39121
More information about the cfe-commits
mailing list