The check now recognizes error cases like new char[strlen(s + 1)] and suggests a fix in the format new char[strlen(s) + 1].
Details
Details
Diff Detail
Diff Detail
Event Timeline
clang-tidy/bugprone/MisplacedOperatorInStrlenInAllocCheck.cpp | ||
---|---|---|
62 | Break after if condition. You could use the ternary operator, too. Maybe a safeguard assertion if Alloc is nullptr after the second assignemt. This would uncover a potential bug. |
clang-tidy/bugprone/MisplacedOperatorInStrlenInAllocCheck.cpp | ||
---|---|---|
64–65 | The backticks should be single quotes instead, I think. | |
test/clang-tidy/bugprone-misplaced-operator-in-strlen-in-alloc.cpp | ||
39 | Please add tests showing that the correct behavior does not diagnose. Also, please add a test showing that this works with overloaded operator new[](). |
clang-tidy/bugprone/MisplacedOperatorInStrlenInAllocCheck.cpp | ||
---|---|---|
64–65 | Missed the backticks around CXXNewExpr |
Break after if condition. You could use the ternary operator, too.
Maybe a safeguard assertion if Alloc is nullptr after the second assignemt. This would uncover a potential bug.