diff --git a/lib/checksizeof.cpp b/lib/checksizeof.cpp index 73bb5cd8b..e42950aed 100644 --- a/lib/checksizeof.cpp +++ b/lib/checksizeof.cpp @@ -157,6 +157,8 @@ void CheckSizeof::checkSizeofForPointerSize() if (tokFunc && tokSize) { for (const Token* tok2 = tokSize; tok2 != tokFunc->linkAt(1); tok2 = tok2->next()) { + if (tok2->str() == "sizeof") + break; if (Token::simpleMatch(tok2, "/ sizeof")) divideBySizeofError(tok2, tokFunc->str()); } diff --git a/test/testsizeof.cpp b/test/testsizeof.cpp index ca6acff65..8ffbc4b5e 100644 --- a/test/testsizeof.cpp +++ b/test/testsizeof.cpp @@ -623,6 +623,12 @@ private: " return malloc(num / sizeof(Foo));\n" "}"); ASSERT_EQUALS("[test.cpp:2]: (warning) Division by result of sizeof(). malloc() expects a size in bytes, did you intend to multiply instead?\n", errout.str()); + + check("void f() {\n" + " char str[100];\n" + " strncpy(str, xyz, sizeof(str)/sizeof(str[0]));\n" + "}"); + ASSERT_EQUALS("", errout.str()); } void sizeofVoid() {