Fixed false negatives incompleteArrayFill on user defined types (estimate size to determine if it is larger than one byte)

Merged from LCppC.
This commit is contained in:
PKEuS 2021-02-24 21:48:04 +01:00 committed by Daniel Marjamäki
parent 2baeeeb02f
commit c25b4f1ad6
2 changed files with 3 additions and 1 deletions

View File

@ -2556,6 +2556,8 @@ void CheckOther::checkIncompleteArrayFill()
int size = mTokenizer->sizeOfType(var->typeStartToken()); int size = mTokenizer->sizeOfType(var->typeStartToken());
if (size == 0 && var->valueType()->pointer) if (size == 0 && var->valueType()->pointer)
size = mSettings->sizeof_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 ((size != 1 && size != 100 && size != 0) || var->isPointer()) {
if (printWarning) if (printWarning)
incompleteArrayFillError(tok, var->name(), tok->str(), false); incompleteArrayFillError(tok, var->name(), tok->str(), false);

View File

@ -6758,7 +6758,7 @@ private:
" Foo a[5];\n" " Foo a[5];\n"
" memset(a, '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" check("void f() {\n"
" Foo a[5];\n" // Size of foo is unknown " Foo a[5];\n" // Size of foo is unknown