From c25b4f1ad6d4400f837b0c1890929c71f31b7111 Mon Sep 17 00:00:00 2001 From: PKEuS Date: Wed, 24 Feb 2021 21:48:04 +0100 Subject: [PATCH] Fixed false negatives incompleteArrayFill on user defined types (estimate size to determine if it is larger than one byte) Merged from LCppC. --- lib/checkother.cpp | 2 ++ test/testother.cpp | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index a01d491eb..6ec9e0706 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -2556,6 +2556,8 @@ void CheckOther::checkIncompleteArrayFill() int size = mTokenizer->sizeOfType(var->typeStartToken()); if (size == 0 && var->valueType()->pointer) size = mSettings->sizeof_pointer; + else if (size == 0 && var->type()) + size = estimateSize(var->type(), mSettings, symbolDatabase); if ((size != 1 && size != 100 && size != 0) || var->isPointer()) { if (printWarning) incompleteArrayFillError(tok, var->name(), tok->str(), false); diff --git a/test/testother.cpp b/test/testother.cpp index 6dd1c49ae..fcbebbb95 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -6758,7 +6758,7 @@ private: " Foo a[5];\n" " memset(a, 'a', 5);\n" "}"); - TODO_ASSERT_EQUALS("[test.cpp:4]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'?\n", "", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'?\n", errout.str()); check("void f() {\n" " Foo a[5];\n" // Size of foo is unknown