Repository navigation
Conversation
| const Token* rhs = tok->astOperand2(); | ||
| // Do not warn about assignment with 0 / NULL | ||
| if (Token::simpleMatch(tok->astOperand2(), "0") || FwdAnalysis::isNullOperand(tok->astOperand2())) | ||
| if ((rhs && rhs->isNumber() && MathLib::isNullValue(rhs->str())) || isNullOperand(rhs)) |
There was a problem hiding this comment.
Is this rhs->isNumber() needed?
There was a problem hiding this comment.
I'll remove it.
There was a problem hiding this comment.
Actually, we need it because isNullValue doesn't check that it's input is a number, causing for example isNullValue(-ENOMEM) to be true... I'll remove the check here and add the check to isNullValue() instead.
| { | ||
| if (!expr) | ||
| return false; | ||
| if (Token::Match(expr, "( %name% %name%| * )") && |
There was a problem hiding this comment.
Maybe we could handle c++ casts better.
Something like:
if (!expr->isCast())
return Token::Match(expr, "NULL|nullptr");
if (expr->valueType() && expr->valueType()->pointer == 0)
return false;
const Token *castOp = expr->astOperand2() ? expr->astOperand2() : expr->astOperand1();
return Token::Match(castOp, "NULL|nullptr") || (MathLib::isInt(castOp->str()) && MathLib::isNullValue(castOp->str()));
There was a problem hiding this comment.
I didn't get isCast() true for any tokens in static_cast<int*>(0) (is this the expected outcome?) so I hade to add an explicit check for the c++ casts. Perhaps there should be a helper for this, it seems like it could be used in many places?
There was a problem hiding this comment.
strange. The isCast() should be true for the ( token. We can fix that separately.
There was a problem hiding this comment.
strange. The isCast() should be true for the ( token. We can fix that separately.
I can reproduce this. It feels like a bug. Maybe there is something I am missing.
Also handle cast of NULL.
Technically, it's not really an FP, but I think it's inconsistent that assigning with
0gives no warning, and0Ugives a warning.