diff --git a/lib/checkfunctions.cpp b/lib/checkfunctions.cpp index c84000d9e..5ad20b5de 100644 --- a/lib/checkfunctions.cpp +++ b/lib/checkfunctions.cpp @@ -328,7 +328,7 @@ void CheckFunctions::memsetZeroBytes() if (WRONG_DATA(arguments.size() != 3U, tok)) continue; const Token* lastParamTok = arguments[2]; - if (lastParamTok->str() == "0") + if (MathLib::isNullValue(lastParamTok->str())) memsetZeroBytesError(tok); } } diff --git a/lib/mathlib.cpp b/lib/mathlib.cpp index d8f8d8b4b..b6b3b4393 100644 --- a/lib/mathlib.cpp +++ b/lib/mathlib.cpp @@ -1293,7 +1293,9 @@ std::string MathLib::tan(const std::string &tok) std::string MathLib::abs(const std::string &tok) { - return toString(std::abs(toDoubleNumber(tok))); + if (isNegative(tok)) + return tok.substr(1, tok.length() - 1); + return tok; } bool MathLib::isEqual(const std::string &first, const std::string &second) diff --git a/lib/platform.h b/lib/platform.h index 92921e0db..2d83b7393 100644 --- a/lib/platform.h +++ b/lib/platform.h @@ -60,10 +60,22 @@ namespace cppcheck { return value >= min_value(int_bit) && value <= max_value(int_bit); } + bool isIntValue(unsigned long long value) const { + return value <= max_value(int_bit); + } + bool isLongValue(long long value) const { return value >= min_value(long_bit) && value <= max_value(long_bit); } + bool isLongValue(unsigned long long value) const { + return value <= max_value(long_bit); + } + + bool isLongLongValue(unsigned long long value) const { + return value <= max_value(long_long_bit); + } + nonneg int char_bit; /// bits in char nonneg int short_bit; /// bits in short nonneg int int_bit; /// bits in int diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 26b21c16a..227445d4e 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -5752,31 +5752,41 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings) type = ValueType::Type::LONGDOUBLE; setValueType(tok, ValueType(ValueType::Sign::UNKNOWN_SIGN, type, 0U)); } else if (MathLib::isInt(tok->str())) { - const bool unsignedSuffix = (tok->str().find_last_of("uU") != std::string::npos); + const std::string tokStr = MathLib::abs(tok->str()); + const bool unsignedSuffix = (tokStr.find_last_of("uU") != std::string::npos); ValueType::Sign sign = unsignedSuffix ? ValueType::Sign::UNSIGNED : ValueType::Sign::SIGNED; - ValueType::Type type; - const MathLib::bigint value = MathLib::toLongNumber(tok->str()); - if (mSettings->platformType == cppcheck::Platform::Unspecified) - type = ValueType::Type::INT; - else if (mSettings->isIntValue(unsignedSuffix ? (value >> 1) : value)) - type = ValueType::Type::INT; - else if (mSettings->isLongValue(unsignedSuffix ? (value >> 1) : value)) - type = ValueType::Type::LONG; - else - type = ValueType::Type::LONGLONG; - if (MathLib::isIntHex(tok->str())) - sign = ValueType::Sign::UNSIGNED; - for (std::size_t pos = tok->str().size() - 1U; pos > 0U; --pos) { - const char suffix = tok->str()[pos]; + ValueType::Type type = ValueType::Type::INT; + const MathLib::biguint value = MathLib::toULongNumber(tokStr); + for (std::size_t pos = tokStr.size() - 1U; pos > 0U; --pos) { + const char suffix = tokStr[pos]; if (suffix == 'u' || suffix == 'U') sign = ValueType::Sign::UNSIGNED; else if (suffix == 'l' || suffix == 'L') type = (type == ValueType::Type::INT) ? ValueType::Type::LONG : ValueType::Type::LONGLONG; - else if (pos > 2U && suffix == '4' && tok->str()[pos - 1] == '6' && tok->str()[pos - 2] == 'i') { + else if (pos > 2U && suffix == '4' && tokStr[pos - 1] == '6' && tokStr[pos - 2] == 'i') { type = ValueType::Type::LONGLONG; pos -= 2; } else break; } + if (mSettings->platformType != cppcheck::Platform::Unspecified) { + if (type <= ValueType::Type::INT && mSettings->isIntValue(unsignedSuffix ? (value >> 1) : value)) + type = ValueType::Type::INT; + else if (type <= ValueType::Type::INT && !MathLib::isDec(tokStr) && mSettings->isIntValue(value >> 2)) { + type = ValueType::Type::INT; + sign = ValueType::Sign::UNSIGNED; + } else if (type <= ValueType::Type::LONG && mSettings->isLongValue(unsignedSuffix ? (value >> 1) : value)) + type = ValueType::Type::LONG; + else if (type <= ValueType::Type::LONG && !MathLib::isDec(tokStr) && mSettings->isLongValue(value >> 2)) { + type = ValueType::Type::LONG; + sign = ValueType::Sign::UNSIGNED; + } else if (mSettings->isLongLongValue(unsignedSuffix ? (value >> 1) : value)) + type = ValueType::Type::LONGLONG; + else { + type = ValueType::Type::LONGLONG; + sign = ValueType::Sign::UNSIGNED; + } + } + setValueType(tok, ValueType(sign, type, 0U)); } } else if (tok->isComparisonOp() || tok->tokType() == Token::eLogicalOp) { diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index 9b410d977..fe4b6e603 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -132,20 +132,6 @@ void TokenList::addtoken(std::string str, const nonneg int lineno, const nonneg } } - // Replace hexadecimal value with decimal - const bool isHex = MathLib::isIntHex(str) ; - if (isHex || MathLib::isOct(str) || MathLib::isBin(str)) { - // TODO: It would be better if TokenList didn't simplify hexadecimal numbers - std::string suffix; - if (isHex && - str.size() == (2 + mSettings->int_bit / 4) && - (str[2] >= '8') && // includes A-F and a-f - MathLib::getSuffix(str).empty() - ) - suffix = "U"; - str = MathLib::value(str).str() + suffix; - } - if (mTokensFrontBack.back) { mTokensFrontBack.back->insertToken(str); } else { @@ -165,20 +151,6 @@ void TokenList::addtoken(std::string str, const Token *locationTok) if (str.empty()) return; - // Replace hexadecimal value with decimal - const bool isHex = MathLib::isIntHex(str) ; - if (isHex || MathLib::isOct(str) || MathLib::isBin(str)) { - // TODO: It would be better if TokenList didn't simplify hexadecimal numbers - std::string suffix; - if (isHex && - str.size() == (2 + mSettings->int_bit / 4) && - (str[2] >= '8') && // includes A-F and a-f - MathLib::getSuffix(str).empty() - ) - suffix = "U"; - str = MathLib::value(str).str() + suffix; - } - if (mTokensFrontBack.back) { mTokensFrontBack.back->insertToken(str); } else { @@ -366,22 +338,6 @@ void TokenList::createTokens(const simplecpp::TokenList *tokenList) std::string str = tok->str(); - // Replace hexadecimal value with decimal - // TODO: Remove this - const bool isHex = MathLib::isIntHex(str) ; - if (isHex || MathLib::isOct(str) || MathLib::isBin(str)) { - // TODO: It would be better if TokenList didn't simplify hexadecimal numbers - std::string suffix; - if (isHex && - mSettings && - str.size() == (2 + mSettings->int_bit / 4) && - (str[2] >= '8') && // includes A-F and a-f - MathLib::getSuffix(str).empty() - ) - suffix = "U"; - str = MathLib::value(str).str() + suffix; - } - // Float literal if (str.size() > 1 && str[0] == '.' && std::isdigit(str[1])) str = '0' + str; diff --git a/test/testcondition.cpp b/test/testcondition.cpp index 131b61760..e7a970e7b 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -167,7 +167,7 @@ private: " int y = x | 0x14;\n" " if (y == 0x710);\n" "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) Mismatching assignment and comparison, comparison 'y==1808' is always false.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) Mismatching assignment and comparison, comparison 'y==0x710' is always false.\n", errout.str()); check("void foo(int x) {\n" " int y = x | 0x14;\n" diff --git a/test/testmathlib.cpp b/test/testmathlib.cpp index fc4b0c67d..403def5dd 100644 --- a/test/testmathlib.cpp +++ b/test/testmathlib.cpp @@ -1157,13 +1157,15 @@ private: ASSERT_EQUALS("0.0", MathLib::tan("0")); } void abs() const { - ASSERT_EQUALS("0.0", MathLib::abs("0")); - ASSERT_EQUALS("0.0", MathLib::abs("+0")); - ASSERT_EQUALS("0.0", MathLib::abs("-0")); - ASSERT_EQUALS("1.0", MathLib::abs("+1")); - ASSERT_EQUALS("1.0", MathLib::abs("+1.0")); - ASSERT_EQUALS("1.0", MathLib::abs("-1")); + ASSERT_EQUALS("", MathLib::abs("")); + ASSERT_EQUALS("0", MathLib::abs("0")); + ASSERT_EQUALS("+0", MathLib::abs("+0")); + ASSERT_EQUALS("0", MathLib::abs("-0")); + ASSERT_EQUALS("+1", MathLib::abs("+1")); + ASSERT_EQUALS("+1.0", MathLib::abs("+1.0")); + ASSERT_EQUALS("1", MathLib::abs("-1")); ASSERT_EQUALS("1.0", MathLib::abs("-1.0")); + ASSERT_EQUALS("9007199254740991", MathLib::abs("9007199254740991")); } void toString() const { diff --git a/test/testother.cpp b/test/testother.cpp index 7869074f9..3d650cd60 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -4296,7 +4296,7 @@ private: " if ((x == 1) && (x == 0x00000001))\n" " a++;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Same expression on both sides of '&&'.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (style) Same expression on both sides of '&&' because 'x==1' and 'x==0x00000001' represent the same value.\n", errout.str()); check("void f() {\n" " enum { Four = 4 };\n" @@ -8300,13 +8300,13 @@ private: "void f(int x) {\n" " g((x & 0x01) >> 7);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (style) Argument '(x&1)>>7' to function g is always 0\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (style) Argument '(x&0x01)>>7' to function g is always 0\n", errout.str()); check("void g(int);\n" "void f(int x) {\n" " g((int)((x & 0x01) >> 7));\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (style) Argument '(int)((x&1)>>7)' to function g is always 0\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (style) Argument '(int)((x&0x01)>>7)' to function g is always 0\n", errout.str()); check("void g(int);\n" "void f(int x) {\n" diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 29161a4dd..cf18174d1 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -3090,7 +3090,7 @@ private: void cAlternativeTokens() { ASSERT_EQUALS("void f ( ) { err |= ( ( r & s ) && ! t ) ; }", tok("void f() { err or_eq ((r bitand s) and not t); }", "test.c", false)); - ASSERT_EQUALS("void f ( ) const { r = f ( a [ 4 ] | 15 , ~ c , ! d ) ; }", + ASSERT_EQUALS("void f ( ) const { r = f ( a [ 4 ] | 0x0F , ~ c , ! d ) ; }", tok("void f() const { r = f(a[4] bitor 0x0F, compl c, not d) ; }", "test.c", false)); } @@ -3386,12 +3386,12 @@ private: { const char code[] = "int vals[] = { 0x13, 1?0x01:0x00 };"; - ASSERT_EQUALS("int vals [ 2 ] = { 19 , 1 } ;", tok(code)); + ASSERT_EQUALS("int vals [ 2 ] = { 0x13 , 0x01 } ;", tok(code)); } { const char code[] = "int vals[] = { 0x13, 0?0x01:0x00 };"; - ASSERT_EQUALS("int vals [ 2 ] = { 19 , 0 } ;", tok(code)); + ASSERT_EQUALS("int vals [ 2 ] = { 0x13 , 0x00 } ;", tok(code)); } { @@ -4901,7 +4901,7 @@ private: " unsigned char override[] = {0x01, 0x02};\n" " doSomething(override, sizeof(override));\n" "}\n"; - ASSERT_EQUALS("void fun ( ) { char override [ 2 ] = { 1 , 2 } ; doSomething ( override , 2 ) ; }", + ASSERT_EQUALS("void fun ( ) { char override [ 2 ] = { 0x01 , 0x02 } ; doSomething ( override , 2 ) ; }", tok(code, true)); } diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index 18c7fff86..0bd77b223 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -6496,12 +6496,37 @@ private: s.long_bit = 32; s.long_long_bit = 64; + Settings sSameSize; + sSameSize.int_bit = 32; + sSameSize.long_bit = 64; + sSameSize.long_long_bit = 64; + // numbers ASSERT_EQUALS("signed int", typeOf("1;", "1", "test.c", &s)); + ASSERT_EQUALS("signed int", typeOf("(-1);", "-1", "test.c", &s)); ASSERT_EQUALS("signed int", typeOf("32767;", "32767", "test.c", &s)); + ASSERT_EQUALS("signed int", typeOf("(-32767);", "-32767", "test.c", &s)); ASSERT_EQUALS("signed long", typeOf("32768;", "32768", "test.c", &s)); + ASSERT_EQUALS("signed long", typeOf("(-32768);", "-32768", "test.c", &s)); + ASSERT_EQUALS("signed long", typeOf("32768l;", "32768l", "test.c", &s)); ASSERT_EQUALS("unsigned int", typeOf("32768U;", "32768U", "test.c", &s)); ASSERT_EQUALS("signed long long", typeOf("2147483648;", "2147483648", "test.c", &s)); + ASSERT_EQUALS("unsigned long", typeOf("2147483648u;", "2147483648u", "test.c", &s)); + ASSERT_EQUALS("signed long long", typeOf("2147483648L;", "2147483648L", "test.c", &s)); + ASSERT_EQUALS("unsigned long long", typeOf("18446744069414584320;", "18446744069414584320", "test.c", &s)); + ASSERT_EQUALS("signed int", typeOf("0xFF;", "0xFF", "test.c", &s)); + ASSERT_EQUALS("unsigned int", typeOf("0xFFU;", "0xFFU", "test.c", &s)); + ASSERT_EQUALS("unsigned int", typeOf("0xFFFF;", "0xFFFF", "test.c", &s)); + ASSERT_EQUALS("signed long", typeOf("0xFFFFFF;", "0xFFFFFF", "test.c", &s)); + ASSERT_EQUALS("unsigned long", typeOf("0xFFFFFFU;", "0xFFFFFFU", "test.c", &s)); + ASSERT_EQUALS("unsigned long", typeOf("0xFFFFFFFF;", "0xFFFFFFFF", "test.c", &s)); + ASSERT_EQUALS("signed long long", typeOf("0xFFFFFFFFFFFF;", "0xFFFFFFFFFFFF", "test.c", &s)); + ASSERT_EQUALS("unsigned long long", typeOf("0xFFFFFFFFFFFFU;", "0xFFFFFFFFFFFFU", "test.c", &s)); + ASSERT_EQUALS("unsigned long long", typeOf("0xFFFFFFFF00000000;", "0xFFFFFFFF00000000", "test.c", &s)); + + ASSERT_EQUALS("signed long", typeOf("2147483648;", "2147483648", "test.c", &sSameSize)); + ASSERT_EQUALS("unsigned long", typeOf("0xc000000000000000;", "0xc000000000000000", "test.c", &sSameSize)); + ASSERT_EQUALS("unsigned int", typeOf("1U;", "1U")); ASSERT_EQUALS("signed long", typeOf("1L;", "1L")); ASSERT_EQUALS("unsigned long", typeOf("1UL;", "1UL")); @@ -6516,11 +6541,26 @@ private: ASSERT_EQUALS("signed long long", typeOf("1ll;", "1ll")); ASSERT_EQUALS("unsigned long long", typeOf("1ull;", "1ull")); ASSERT_EQUALS("unsigned long long", typeOf("1llu;", "1llu")); + ASSERT_EQUALS("signed int", typeOf("01;", "01")); + ASSERT_EQUALS("unsigned int", typeOf("01U;", "01U")); + ASSERT_EQUALS("signed long", typeOf("01L;", "01L")); + ASSERT_EQUALS("unsigned long", typeOf("01UL;", "01UL")); + ASSERT_EQUALS("signed long long", typeOf("01LL;", "01LL")); + ASSERT_EQUALS("unsigned long long", typeOf("01ULL;", "01ULL")); + ASSERT_EQUALS("signed int", typeOf("0B1;", "0B1")); + ASSERT_EQUALS("signed int", typeOf("0b1;", "0b1")); + ASSERT_EQUALS("unsigned int", typeOf("0b1U;", "0b1U")); + ASSERT_EQUALS("signed long", typeOf("0b1L;", "0b1L")); + ASSERT_EQUALS("unsigned long", typeOf("0b1UL;", "0b1UL")); + ASSERT_EQUALS("signed long long", typeOf("0b1LL;", "0b1LL")); + ASSERT_EQUALS("unsigned long long", typeOf("0b1ULL;", "0b1ULL")); ASSERT_EQUALS("float", typeOf("1.0F;", "1.0F")); ASSERT_EQUALS("float", typeOf("1.0f;", "1.0f")); ASSERT_EQUALS("double", typeOf("1.0;", "1.0")); ASSERT_EQUALS("double", typeOf("1E3;", "1E3")); + ASSERT_EQUALS("double", typeOf("0x1.2p3;", "0x1.2p3")); ASSERT_EQUALS("long double", typeOf("1.23L;", "1.23L")); + ASSERT_EQUALS("long double", typeOf("1.23l;", "1.23l")); // Constant calculations ASSERT_EQUALS("signed int", typeOf("1 + 2;", "+")); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index d83824152..497387fb8 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -622,7 +622,7 @@ private: ASSERT_EQUALS("; x = ( a + m ) & p [ n ] ;", tokenizeAndStringify("; x = ( a + m ) & p [ n ] ;", true));*/ // "*(p+1)" => "p[1]" ASSERT_EQUALS("; x = p [ 1 ] ;", tokenizeAndStringify("; x = * ( p + 1 ) ;", true)); - ASSERT_EQUALS("; x = p [ 10 ] ;", tokenizeAndStringify("; x = * ( p + 0xA ) ;", true)); + ASSERT_EQUALS("; x = p [ 0xA ] ;", tokenizeAndStringify("; x = * ( p + 0xA ) ;", true)); ASSERT_EQUALS("; x = p [ n ] ;", tokenizeAndStringify("; x = * ( p + n ) ;", true)); ASSERT_EQUALS("; x = y * ( p + n ) ;", tokenizeAndStringify("; x = y * ( p + n ) ;", true)); ASSERT_EQUALS("; x = 10 * ( p + n ) ;", tokenizeAndStringify("; x = 10 * ( p + n ) ;", true)); @@ -631,7 +631,7 @@ private: // "*(p-1)" => "p[-1]" and "*(p-n)" => "p[-n]" ASSERT_EQUALS("; x = p [ -1 ] ;", tokenizeAndStringify("; x = *(p - 1);", true)); - ASSERT_EQUALS("; x = p [ -10 ] ;", tokenizeAndStringify("; x = *(p - 0xA);", true)); + ASSERT_EQUALS("; x = p [ -0xA ] ;", tokenizeAndStringify("; x = *(p - 0xA);", true)); ASSERT_EQUALS("; x = p [ - n ] ;", tokenizeAndStringify("; x = *(p - n);", true)); ASSERT_EQUALS("; x = y * ( p - 1 ) ;", tokenizeAndStringify("; x = y * (p - 1);", true)); ASSERT_EQUALS("; x = 10 * ( p - 1 ) ;", tokenizeAndStringify("; x = 10 * (p - 1);", true)); @@ -700,21 +700,21 @@ private: // Ticket #2361: 0X10 => 16 void tokenize14() { - ASSERT_EQUALS("; 16 ;", tokenizeAndStringify(";0x10;")); - ASSERT_EQUALS("; 16 ;", tokenizeAndStringify(";0X10;")); - ASSERT_EQUALS("; 292 ;", tokenizeAndStringify(";0444;")); + ASSERT_EQUALS("; 0x10 ;", tokenizeAndStringify(";0x10;")); + ASSERT_EQUALS("; 0X10 ;", tokenizeAndStringify(";0X10;")); + ASSERT_EQUALS("; 0444 ;", tokenizeAndStringify(";0444;")); } // Ticket #8050 void tokenizeHexWithSuffix() { - ASSERT_EQUALS("; 16777215 ;", tokenizeAndStringify(";0xFFFFFF;")); - ASSERT_EQUALS("; 16777215U ;", tokenizeAndStringify(";0xFFFFFFu;")); - ASSERT_EQUALS("; 16777215UL ;", tokenizeAndStringify(";0xFFFFFFul;")); + ASSERT_EQUALS("; 0xFFFFFF ;", tokenizeAndStringify(";0xFFFFFF;")); + ASSERT_EQUALS("; 0xFFFFFFu ;", tokenizeAndStringify(";0xFFFFFFu;")); + ASSERT_EQUALS("; 0xFFFFFFul ;", tokenizeAndStringify(";0xFFFFFFul;")); // Number of digits decides about internal representation... - ASSERT_EQUALS("; 4294967295U ;", tokenizeAndStringify(";0xFFFFFFFF;")); - ASSERT_EQUALS("; 4294967295U ;", tokenizeAndStringify(";0xFFFFFFFFu;")); - ASSERT_EQUALS("; 4294967295UL ;", tokenizeAndStringify(";0xFFFFFFFFul;")); + ASSERT_EQUALS("; 0xFFFFFFFF ;", tokenizeAndStringify(";0xFFFFFFFF;")); + ASSERT_EQUALS("; 0xFFFFFFFFu ;", tokenizeAndStringify(";0xFFFFFFFFu;")); + ASSERT_EQUALS("; 0xFFFFFFFFul ;", tokenizeAndStringify(";0xFFFFFFFFul;")); } // Ticket #2429: 0.125 @@ -757,7 +757,7 @@ private: } void tokenize21() { // tokenize 0x0E-7 - ASSERT_EQUALS("14 - 7 ;", tokenizeAndStringify("0x0E-7;")); + ASSERT_EQUALS("0x0E - 7 ;", tokenizeAndStringify("0x0E-7;")); } void tokenize22() { // tokenize special marker $ from preprocessor @@ -2981,7 +2981,7 @@ private: "char * p ;\n" "char * q ;\n" "\n" - "switch ( x & 3 )\n" + "switch ( x & 0x3 )\n" "{\n" "case 1 : ;\n" "p = x ;\n" @@ -3125,7 +3125,7 @@ private: { const char code[] = "module ( a , a , sizeof ( a ) , 0444 ) ;"; - ASSERT_EQUALS("module ( a , a , sizeof ( a ) , 292 ) ;", tokenizeAndStringify(code)); + ASSERT_EQUALS("module ( a , a , sizeof ( a ) , 0444 ) ;", tokenizeAndStringify(code)); } ASSERT_EQUALS("void f ( int x ) { }", tokenizeAndStringify("void f(x) int x; { }")); diff --git a/test/testtokenlist.cpp b/test/testtokenlist.cpp index 5e29756a9..5113317d1 100644 --- a/test/testtokenlist.cpp +++ b/test/testtokenlist.cpp @@ -21,7 +21,6 @@ #include "token.h" #include "tokenlist.h" -#include #include class TestTokenList : public TestFixture { @@ -43,14 +42,7 @@ private: const std::string code = "0x89504e470d0a1a0a"; TokenList tokenlist(&settings); tokenlist.addtoken(code, 1, 1, false); - ASSERT_EQUALS("9894494448401390090U", tokenlist.front()->str()); - // that is supposed to break on 32bit - //unsigned long numberUL(0); - //std::istringstream(tokenlist.front()->str()) >> numberUL; - //ASSERT_EQUALS(9894494448401390090U, numberUL); - unsigned long long numberULL(0); - std::istringstream(tokenlist.front()->str()) >> numberULL; - ASSERT_EQUALS(9894494448401390090U, numberULL); + ASSERT_EQUALS("0x89504e470d0a1a0a", tokenlist.front()->str()); } void testaddtoken2() { @@ -58,7 +50,7 @@ private: settings.int_bit = 32; TokenList tokenlist(&settings); tokenlist.addtoken(code, 1, 1, false); - ASSERT_EQUALS("4026531840U", tokenlist.front()->str()); + ASSERT_EQUALS("0xF0000000", tokenlist.front()->str()); } void inc() const { diff --git a/test/testtype.cpp b/test/testtype.cpp index 956feadec..3a46897f3 100644 --- a/test/testtype.cpp +++ b/test/testtype.cpp @@ -212,10 +212,10 @@ private: settings.addEnabled("warning"); check("x = (int)0x10000 * (int)0x10000;", &settings); - ASSERT_EQUALS("[test.cpp:1]: (error) Signed integer overflow for expression '(int)65536*(int)65536'.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:1]: (error) Signed integer overflow for expression '(int)0x10000*(int)0x10000'.\n", errout.str()); check("x = (long)0x10000 * (long)0x10000;", &settings); - ASSERT_EQUALS("[test.cpp:1]: (error) Signed integer overflow for expression '(long)65536*(long)65536'.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:1]: (error) Signed integer overflow for expression '(long)0x10000*(long)0x10000'.\n", errout.str()); check("void foo() {\n" " int intmax = 0x7fffffff;\n" diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 6ff89e20f..db243a096 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -334,7 +334,7 @@ private: ASSERT_EQUALS(0, valueOfTok("x(NULL);", "NULL").intvalue); ASSERT_EQUALS((int)('a'), valueOfTok("x='a';", "'a'").intvalue); ASSERT_EQUALS((int)('\n'), valueOfTok("x='\\n';", "'\\n'").intvalue); - ASSERT_EQUALS(0xFFFFFFFF00000000, valueOfTok("x=0xFFFFFFFF00000000;","18446744069414584320U").intvalue); // #7701 + ASSERT_EQUALS(0xFFFFFFFF00000000, valueOfTok("x=0xFFFFFFFF00000000;","0xFFFFFFFF00000000").intvalue); // #7701 // scope {