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