Fixed #7885 (ValueType: Wrong type for large hexvalue (platform=win32A))

This commit is contained in:
Daniel Marjamäki 2017-03-04 14:19:14 +01:00
parent ecc59859e1
commit 12fe4a8b3e
2 changed files with 5 additions and 3 deletions

View File

@ -4743,14 +4743,15 @@ void SymbolDatabase::setValueTypeInTokenList(Token *tokens, bool cpp, const Sett
type = ValueType::Type::LONGDOUBLE;
::setValueType(tok, ValueType(ValueType::Sign::UNKNOWN_SIGN, type, 0U), cpp, defsign, settings);
} else if (MathLib::isInt(tok->str())) {
ValueType::Sign sign = ValueType::Sign::SIGNED;
bool unsignedSuffix = (tok->str().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 (settings->platformType == cppcheck::Platform::Unspecified)
type = ValueType::Type::INT;
else if (settings->isIntValue(value))
else if (settings->isIntValue(unsignedSuffix ? (value >> 1) : value))
type = ValueType::Type::INT;
else if (settings->isLongValue(value))
else if (settings->isLongValue(unsignedSuffix ? (value >> 1) : value))
type = ValueType::Type::LONG;
else
type = ValueType::Type::LONGLONG;

View File

@ -4120,6 +4120,7 @@ private:
ASSERT_EQUALS("signed int", typeOf("1;", "1", "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("unsigned int", typeOf("32768U;", "32768U", "test.c", &s));
ASSERT_EQUALS("signed long long", typeOf("2147483648;", "2147483648", "test.c", &s));
ASSERT_EQUALS("unsigned int", typeOf("1U;", "1U"));
ASSERT_EQUALS("signed long", typeOf("1L;", "1L"));