diff --git a/lib/checktype.cpp b/lib/checktype.cpp index 68e857d4a1d..65162374a69 100644 --- a/lib/checktype.cpp +++ b/lib/checktype.cpp @@ -294,9 +294,9 @@ static bool isSmallerTypeSize(const ValueType* a, const ValueType* b, const Toke { std::string strArr[] = { a->str(), b->str() }; for (std::string& s : strArr) { - const std::size_t pos = s.rfind(' '); // get bare type string + const std::size_t pos = s.find("signed"); // get bare type string if (pos != std::string::npos) - s.erase(s.begin(), s.begin() + pos + 1); + s.erase(s.begin(), s.begin() + pos + 6 + 1); } return tokenizer->sizeOfType(strArr[0]) < tokenizer->sizeOfType(strArr[1]); } diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 4bb7268f5d9..a0fd9e5fc87 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -3427,8 +3427,10 @@ void Tokenizer::fillTypeSizes() mTypeSize["short"] = mSettings->platform.sizeof_short; mTypeSize["int"] = mSettings->platform.sizeof_int; mTypeSize["long"] = mSettings->platform.sizeof_long; + mTypeSize["long long"] = mSettings->platform.sizeof_long_long; mTypeSize["float"] = mSettings->platform.sizeof_float; mTypeSize["double"] = mSettings->platform.sizeof_double; + mTypeSize["long double"] = mSettings->platform.sizeof_long_double; mTypeSize["wchar_t"] = mSettings->platform.sizeof_wchar_t; mTypeSize["size_t"] = mSettings->platform.sizeof_size_t; mTypeSize["*"] = mSettings->platform.sizeof_pointer; diff --git a/test/testtype.cpp b/test/testtype.cpp index cb5b2b1b3e7..6d003ad7d44 100644 --- a/test/testtype.cpp +++ b/test/testtype.cpp @@ -363,13 +363,21 @@ class TestType : public TestFixture { const Settings settingsWin = settingsBuilder().severity(Severity::style).platform(cppcheck::Platform::Type::Win64).build(); const char code[] = "long f(int x, int y) {\n" - " return x * y;\n" - "}\n"; + " return x * y;\n" + "}\n"; check(code, settings); ASSERT_EQUALS("[test.cpp:2]: (style) int result is returned as long value. If the return value is long to avoid loss of information, then you have loss of information.\n", errout.str()); check(code, settingsWin); ASSERT_EQUALS("", errout.str()); + const char code2[] = "long long f(int x, int y) {\n" + " return x * y;\n" + "}\n"; + check(code2, settings); + ASSERT_EQUALS("[test.cpp:2]: (style) int result is returned as long value. If the return value is long to avoid loss of information, then you have loss of information.\n", errout.str()); + check(code2, settingsWin); + ASSERT_EQUALS("[test.cpp:2]: (style) int result is returned as long value. If the return value is long to avoid loss of information, then you have loss of information.\n", errout.str()); + // typedef check("size_t f(int x, int y) {\n" " return x * y;\n"