Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/checkio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1539,9 +1539,9 @@
if (element && isStdVectorOrString()) { // isStdVectorOrString sets type token if true
element = false; // not really an array element
} else if (variableInfo->isEnumType()) {
if (variableInfo->type() && variableInfo->type()->classScope && variableInfo->type()->classScope->enumType)
if (variableInfo->type() && variableInfo->type()->classScope && variableInfo->type()->classScope->enumType && variableInfo->type()->classScope->enumType->isStandardType())

Check failure

Code scanning / Cppcheck Premium

Either the condition 'variableInfo->type()' is redundant or there is possible null pointer dereference: variableInfo->type(). High

Either the condition 'variableInfo->type()' is redundant or there is possible null pointer dereference: variableInfo->type().

Check failure

Code scanning / Cppcheck Premium

Either the condition 'variableInfo->type()->classScope' is redundant or there is possible null pointer dereference: variableInfo->type()->classScope. High

Either the condition 'variableInfo->type()->classScope' is redundant or there is possible null pointer dereference: variableInfo->type()->classScope.
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
typeToken = variableInfo->type()->classScope->enumType;
else {
else if (!variableInfo->type()->classScope->enumType) {
tempToken = new Token(tok1);
tempToken->str("int");
typeToken = tempToken;
Expand Down
14 changes: 14 additions & 0 deletions test/testio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3371,6 +3371,20 @@ class TestIO : public TestFixture {
"}");
ASSERT_EQUALS("", errout_str());

check("enum E : uint8_t { E0 }; \n" // #7959
"void f(E e) {\n"
" printf(\"%hhu\", e);\n"
"}");
ASSERT_EQUALS("", errout_str());

check("enum E : uint8_t { E0 }; \n"
"void f(E e) {\n"
" printf(\"%lu\", e);\n"
"}");
TODO_ASSERT_EQUALS("[test.cpp:3]: (warning) %lu in format string (no. 1) requires 'unsigned long' but the argument type is 'uint8_t'.\n",
"",
errout_str());

check("void f() {\n"
" printf(\"%lu\", sizeof(char));\n"
"}\n", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win64));
Expand Down
Loading