diff --git a/lib/checksizeof.cpp b/lib/checksizeof.cpp index c12f507b7..4325d35b5 100644 --- a/lib/checksizeof.cpp +++ b/lib/checksizeof.cpp @@ -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 { diff --git a/test/testsizeof.cpp b/test/testsizeof.cpp index 7fddeee64..bca511067 100644 --- a/test/testsizeof.cpp +++ b/test/testsizeof.cpp @@ -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)