From 12fe4a8b3ea68dde81189bd7e1e2da03405f6479 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 4 Mar 2017 14:19:14 +0100 Subject: [PATCH] Fixed #7885 (ValueType: Wrong type for large hexvalue (platform=win32A)) --- lib/symboldatabase.cpp | 7 ++++--- test/testsymboldatabase.cpp | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index a1e335cf9..7c3d83c3d 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -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; diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index 3cd5b9603..a9bef248c 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -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"));