Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/checkfunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ void CheckFunctions::invalidFunctionUsage()
const SymbolDatabase* symbolDatabase = mTokenizer->getSymbolDatabase();
for (const Scope *scope : symbolDatabase->functionScopes) {
for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) {
tok = skipUnreachableBranch(tok);
if (!Token::Match(tok, "%name% ( !!)"))
continue;
const Token * const functionToken = tok;
Expand Down
18 changes: 18 additions & 0 deletions test/testfunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ class TestFunctions : public TestFixture {
TEST_CASE(invalidFunctionUsage1);
TEST_CASE(invalidFunctionUsageStrings);

// Invalid function argument
TEST_CASE(invalidFunctionArg1);

// Math function usage
TEST_CASE(mathfunctionCall_fmod);
TEST_CASE(mathfunctionCall_sqrt);
Expand Down Expand Up @@ -755,6 +758,21 @@ class TestFunctions : public TestFixture {
ASSERT_EQUALS("[test.c:1]: (error) Invalid puts() argument nr 1. A nul-terminated string is required.\n", errout_str());
}

void invalidFunctionArg1() {
const Settings settingsUnix32 = settingsBuilder(settings).platform(Platform::Unix32).build();
check("int main() {\n"
" char tgt[7];\n"
" char src[7+1] = \"7777777\";\n"
" if (sizeof tgt <= sizeof src) {\n"
" memmove(&tgt, &src, sizeof tgt);\n"
" } else {\n"
" memmove(&tgt, &src, sizeof src);\n"
" memset(&tgt + sizeof src, ' ', sizeof tgt - sizeof src);\n"
" }\n"
"}\n", false, &settingsUnix32);
ASSERT_EQUALS("", errout_str());
}

void mathfunctionCall_sqrt() {
// sqrt, sqrtf, sqrtl
check("void foo()\n"
Expand Down