Show struct member in unsignedLessThanZeroError warning#830
Conversation
|
Should not break anything, I hope. I split |
| pointerLessThanZeroError(tok, inconclusive); | ||
| if (vt && vt->sign == ValueType::UNSIGNED) | ||
| unsignedLessThanZeroError(tok, tok->astOperand1()->str(), inconclusive); | ||
| unsignedLessThanZeroError(tok, tok->operand1String(), inconclusive); |
There was a problem hiding this comment.
why not tok->astOperand1()->expressionString()?
There was a problem hiding this comment.
Hm, didn't thought to try it. Looks like it works. Will fix it.
| return false; // <- guess | ||
| } | ||
|
|
||
| std::string Token::expressionString() const |
There was a problem hiding this comment.
splitting this function is a good idea. Thanks.
| } | ||
|
|
||
| std::string Token::expressionString() const | ||
| const Token* goToLeftParenthesis(const Token* start, const Token* end) |
| " return;\n" | ||
| " }\n" | ||
| "}", "test.c"); | ||
| ASSERT_EQUALS("[test.c:8]: (style) Checking if unsigned variable 'd.n' is less than zero.\n" |
There was a problem hiding this comment.
If there are parentheses around the expression I believe it is ok to remove them:
if ((d.n+1) < 0) {}
[test.c:8]: (style) Checking if unsigned variable 'd.n+1' is less than zero.
Isn't it?
As far as I see the operand1String will output:
[test.c:8]: (style) Checking if unsigned variable '(d.n+1)' is less than zero.
There was a problem hiding this comment.
Somehow after adding parentheses Cppcheck can't find this issue anymore. Is it a bug?
There was a problem hiding this comment.
Oh, I was looking at another test file.
Looks like using tok->astOperand1()->expressionString() fixed this, there are no parentheses in warning.
|
@danmar I've completed changes you requested. Is it good now? |
|
yes it looks good now. as far as I see you should remove the changes in lib/token.h. when that has been done this can be applied. I also think there could be better names but I have no suggestion and these will work for now. |
Before:
[/tmp/test.c:8]: (style) Checking if unsigned variable '.' is less than zero.
[/tmp/test.c:12]: (style) Checking if unsigned variable '.' is less than zero.
After:
[/tmp/test.c:8]: (style) Checking if unsigned variable 'd.n' is less than zero.
[/tmp/test.c:12]: (style) Checking if unsigned variable 'd.n' is less than zero.
|
Oh, missed these header changes. Done. |
Before:
[/tmp/test.c:8]: (style) Checking if unsigned variable '.' is less than zero.
[/tmp/test.c:12]: (style) Checking if unsigned variable '.' is less than zero.
After:
[/tmp/test.c:8]: (style) Checking if unsigned variable 'd.n' is less than zero.
[/tmp/test.c:12]: (style) Checking if unsigned variable 'd.n' is less than zero.