value flow: cleanup usage of valueflow. utility function Token::getValue was added.
This commit is contained in:
parent
98305e9163
commit
69109784e8
|
@ -752,21 +752,12 @@ void CheckNullPointer::nullPointerStructByDeRefAndChec()
|
|||
void CheckNullPointer::nullPointerByDeRefAndChec()
|
||||
{
|
||||
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) {
|
||||
if (!tok->isName() || tok->values.empty())
|
||||
continue;
|
||||
|
||||
const Variable *var = tok->variable();
|
||||
if (!var || !var->isPointer() || tok == var->nameToken())
|
||||
continue;
|
||||
|
||||
// Can pointer be NULL?
|
||||
const ValueFlow::Value *value = 0;
|
||||
for (std::list<ValueFlow::Value>::const_iterator it = tok->values.begin(); it != tok->values.end(); ++it) {
|
||||
if (it->intvalue == 0) {
|
||||
value = &(*it);
|
||||
break;
|
||||
}
|
||||
}
|
||||
const ValueFlow::Value *value = tok->getValue(0);
|
||||
if (!value)
|
||||
continue;
|
||||
|
||||
|
|
|
@ -2185,15 +2185,12 @@ void CheckOther::checkZeroDivision()
|
|||
zerodivError(tok);
|
||||
} else if (Token::Match(tok, "[/%]") && tok->astOperand2() && !tok->astOperand2()->values.empty()) {
|
||||
// Value flow..
|
||||
const std::list<ValueFlow::Value> &values = tok->astOperand2()->values;
|
||||
std::list<ValueFlow::Value>::const_iterator it;
|
||||
for (it = values.begin(); it != values.end(); ++it) {
|
||||
if (it->intvalue == 0) {
|
||||
if (it->condition == NULL)
|
||||
zerodivError(tok);
|
||||
else if (_settings->isEnabled("warning"))
|
||||
zerodivcondError(it->condition,tok);
|
||||
}
|
||||
const ValueFlow::Value *value = tok->astOperand2()->getValue(0LL);
|
||||
if (value) {
|
||||
if (value->condition == NULL)
|
||||
zerodivError(tok);
|
||||
else if (_settings->isEnabled("warning"))
|
||||
zerodivcondError(value->condition,tok);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
10
lib/token.h
10
lib/token.h
|
@ -27,6 +27,7 @@
|
|||
#include <ostream>
|
||||
#include "config.h"
|
||||
#include "valueflow.h"
|
||||
#include "mathlib.h"
|
||||
|
||||
class Scope;
|
||||
class Function;
|
||||
|
@ -580,6 +581,15 @@ public:
|
|||
/** Values of token */
|
||||
std::list<ValueFlow::Value> values;
|
||||
|
||||
const ValueFlow::Value * getValue(const MathLib::bigint val) const {
|
||||
std::list<ValueFlow::Value>::const_iterator it;
|
||||
for (it = values.begin(); it != values.end(); ++it) {
|
||||
if (it->intvalue == val)
|
||||
return &(*it);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
private:
|
||||
void next(Token *nextToken) {
|
||||
_next = nextToken;
|
||||
|
|
Loading…
Reference in New Issue