Skip to content

Commit

Permalink
Set type info
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed Jul 24, 2023
1 parent f5b81ac commit b548bea
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/checktype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
Expand Down
2 changes: 2 additions & 0 deletions lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 10 additions & 2 deletions test/testtype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit b548bea

Please sign in to comment.