Skip to content

Commit 4e92f8d

Browse files
committed
Fixed cppcheck-opensource#4295 (False positive: Expression '(X & 0xFF00000000000000LL)==0xa00000000000000' always evaluates to false (64-bit value))
1 parent ea9f071 commit 4e92f8d

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

‎lib/mathlib.cpp‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,17 @@ MathLib::bigint MathLib::toLongNumber(const std::string &str)
3131
{
3232
// hexadecimal numbers:
3333
if (isHex(str)) {
34-
bigint ret = 0;
35-
std::istringstream istr(str);
36-
istr >> std::hex >> ret;
37-
return ret;
34+
if (str[0] == '-') {
35+
bigint ret = 0;
36+
std::istringstream istr(str);
37+
istr >> std::hex >> ret;
38+
return ret;
39+
} else {
40+
unsigned long long ret = 0;
41+
std::istringstream istr(str);
42+
istr >> std::hex >> ret;
43+
return (bigint)ret;
44+
}
3845
}
3946

4047
// octal numbers:

‎test/testmathlib.cpp‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ class TestMathLib : public TestFixture {
185185
ASSERT_EQUALS(100 , MathLib::toLongNumber("+10.0E+1"));
186186
ASSERT_EQUALS(-1 , MathLib::toLongNumber("-10.0E-1"));
187187

188+
// from long long
189+
ASSERT_EQUALS(0xFF00000000000000LL, MathLib::toLongNumber("0xFF00000000000000LL"));
190+
ASSERT_EQUALS(0x0A00000000000000LL, MathLib::toLongNumber("0x0A00000000000000LL"));
191+
188192
// -----------------
189193
// to double number:
190194
// -----------------

0 commit comments

Comments
 (0)