value flow: cleanup usage of valueflow. utility function Token::getValue was added.

This commit is contained in:
Daniel Marjamäki 2014-01-20 06:49:45 +01:00
parent 98305e9163
commit 69109784e8
3 changed files with 17 additions and 19 deletions

View File

@ -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;

View File

@ -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);
}
}
}

View File

@ -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;