#5895 - Fixed potential signed integer overflow in Checkother:getvalue. Added regression test.
This commit is contained in:
parent
f6c9320aee
commit
6d0f490138
|
@ -1223,7 +1223,7 @@ template<class T> static T getvalue(const int test, const T value1, const T valu
|
||||||
case 2:
|
case 2:
|
||||||
return value1;
|
return value1;
|
||||||
case 3:
|
case 3:
|
||||||
return (value1 + value2) / (T)2;
|
return (T)(value1*0.5 + value2*0.5);
|
||||||
case 4:
|
case 4:
|
||||||
return value2;
|
return value2;
|
||||||
case 5: {
|
case 5: {
|
||||||
|
|
|
@ -196,6 +196,8 @@ private:
|
||||||
TEST_CASE(checkCommaSeparatedReturn);
|
TEST_CASE(checkCommaSeparatedReturn);
|
||||||
|
|
||||||
TEST_CASE(checkComparisonFunctionIsAlwaysTrueOrFalse);
|
TEST_CASE(checkComparisonFunctionIsAlwaysTrueOrFalse);
|
||||||
|
|
||||||
|
TEST_CASE(integerOverflow) // #5895
|
||||||
}
|
}
|
||||||
|
|
||||||
void check(const char code[], const char *filename = nullptr, bool experimental = false, bool inconclusive = true, bool posix = false, bool runSimpleChecks=true, Settings* settings = 0) {
|
void check(const char code[], const char *filename = nullptr, bool experimental = false, bool inconclusive = true, bool posix = false, bool runSimpleChecks=true, Settings* settings = 0) {
|
||||||
|
@ -7246,6 +7248,16 @@ private:
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void integerOverflow() { // 5895
|
||||||
|
// no signed integer overflow should happen
|
||||||
|
check("#define A 0x89504e470d0a1a0a\n"
|
||||||
|
"#define B 0x8a4d4e470d0a1a0a\n"
|
||||||
|
"void f(unsigned long long ull) {\n"
|
||||||
|
" if (ull == A || ull == B);\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
REGISTER_TEST(TestOther)
|
REGISTER_TEST(TestOther)
|
||||||
|
|
Loading…
Reference in New Issue