#5875 fix 'lib/checksizeof.cpp:142:26: runtime error: member call on null pointer of type 'Token'. Improve error handling in CheckSizeof::checkSizeofForPointerSize()

This commit is contained in:
Alexander Mai 2014-06-01 22:18:17 +02:00
parent 7a668bb752
commit ad1662a201
2 changed files with 11 additions and 0 deletions

View File

@ -139,6 +139,8 @@ void CheckSizeof::checkSizeofForPointerSize()
} else if (Token::Match(tok, "memcpy|memcmp|memmove|strncpy|strncmp|strncat (")) {
variable = tok->tokAt(2);
variable2 = variable->nextArgument();
if (!variable2)
continue;
tokVar = variable2->nextArgument();
} else {

View File

@ -40,6 +40,7 @@ private:
TEST_CASE(sizeofForNumericParameter);
TEST_CASE(suspiciousSizeofCalculation);
TEST_CASE(sizeofVoid);
TEST_CASE(customStrncat);
}
void check(const char code[]) {
@ -635,6 +636,14 @@ private:
ASSERT_EQUALS("[test.cpp:5]: (portability) '(foo[0]).data' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined.\n", errout.str());
}
void customStrncat() {
// Ensure we don't crash on custom-defined strncat, ticket #5875
check("char strncat ();\n"
"int main () {\n"
" return strncat ();\n"
"}\n");
}
};
REGISTER_TEST(TestSizeof)