Merge branch 'master' of http://github.com/danmar/cppcheck
This commit is contained in:
commit
d68ad1ae01
|
@ -34,20 +34,6 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
class Settings;
|
|
||||||
class SymbolDatabase;
|
|
||||||
class Token;
|
|
||||||
namespace ValueFlow {
|
|
||||||
class Value;
|
|
||||||
} // namespace ValueFlow
|
|
||||||
namespace tinyxml2 {
|
|
||||||
class XMLElement;
|
|
||||||
} // namespace tinyxml2
|
|
||||||
|
|
||||||
// CWE ids used
|
|
||||||
static const struct CWE CWE119(119U); // Improper Restriction of Operations within the Bounds of a Memory Buffer
|
|
||||||
|
|
||||||
class Variable;
|
|
||||||
|
|
||||||
/// @addtogroup Checks
|
/// @addtogroup Checks
|
||||||
/// @{
|
/// @{
|
||||||
|
|
|
@ -3766,12 +3766,39 @@ static void execute(const Token *expr,
|
||||||
*result = result1 != result2;
|
*result = result1 != result2;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (expr->str() == "=") {
|
else if (expr->isAssignmentOp()) {
|
||||||
execute(expr->astOperand2(), programMemory, result, error);
|
execute(expr->astOperand2(), programMemory, result, error);
|
||||||
if (!*error && expr->astOperand1() && expr->astOperand1()->varId())
|
if (!expr->astOperand1() || !expr->astOperand1()->varId())
|
||||||
programMemory->setIntValue(expr->astOperand1()->varId(), *result);
|
|
||||||
else
|
|
||||||
*error = true;
|
*error = true;
|
||||||
|
if (*error)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (expr->str() == "=") {
|
||||||
|
programMemory->setIntValue(expr->astOperand1()->varId(), *result);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
long long intValue;
|
||||||
|
if (!programMemory->getIntValue(expr->astOperand1()->varId(), &intValue)) {
|
||||||
|
*error = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (expr->str() == "+=")
|
||||||
|
programMemory->setIntValue(expr->astOperand1()->varId(), intValue + *result);
|
||||||
|
else if (expr->str() == "-=")
|
||||||
|
programMemory->setIntValue(expr->astOperand1()->varId(), intValue - *result);
|
||||||
|
else if (expr->str() == "*=")
|
||||||
|
programMemory->setIntValue(expr->astOperand1()->varId(), intValue * *result);
|
||||||
|
else if (expr->str() == "/=" && *result != 0)
|
||||||
|
programMemory->setIntValue(expr->astOperand1()->varId(), intValue / *result);
|
||||||
|
else if (expr->str() == "%=" && *result != 0)
|
||||||
|
programMemory->setIntValue(expr->astOperand1()->varId(), intValue % *result);
|
||||||
|
else if (expr->str() == "&=")
|
||||||
|
programMemory->setIntValue(expr->astOperand1()->varId(), intValue & *result);
|
||||||
|
else if (expr->str() == "|=")
|
||||||
|
programMemory->setIntValue(expr->astOperand1()->varId(), intValue | *result);
|
||||||
|
else if (expr->str() == "^=")
|
||||||
|
programMemory->setIntValue(expr->astOperand1()->varId(), intValue ^ *result);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (Token::Match(expr, "++|--")) {
|
else if (Token::Match(expr, "++|--")) {
|
||||||
|
|
|
@ -2558,6 +2558,13 @@ private:
|
||||||
"}";
|
"}";
|
||||||
ASSERT_EQUALS(true, testValueOfX(code, 3U, 9));
|
ASSERT_EQUALS(true, testValueOfX(code, 3U, 9));
|
||||||
|
|
||||||
|
code = "void f() {\n"
|
||||||
|
" for (int x = 0; x < 5; x += 2)\n"
|
||||||
|
" a[x] = 0;\n"
|
||||||
|
"}";
|
||||||
|
ASSERT_EQUALS(true, testValueOfX(code, 3U, 0));
|
||||||
|
ASSERT_EQUALS(true, testValueOfX(code, 3U, 4));
|
||||||
|
|
||||||
code = "void f() {\n"
|
code = "void f() {\n"
|
||||||
" for (int x = 0; x < 10; x = x + 2)\n"
|
" for (int x = 0; x < 10; x = x + 2)\n"
|
||||||
" a[x] = 0;\n"
|
" a[x] = 0;\n"
|
||||||
|
|
Loading…
Reference in New Issue