Skip to content

Commit

Permalink
Fix #12396 FP nullPointer for pthread_create with function type cast
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed Jan 31, 2024
1 parent 06c8363 commit 2921ba6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/valueflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7863,7 +7863,7 @@ static void setFunctionReturnValue(const Function* f, Token* tok, ValueFlow::Val
static void valueFlowFunctionReturn(TokenList &tokenlist, ErrorLogger *errorLogger, const Settings& settings)
{
for (Token *tok = tokenlist.back(); tok; tok = tok->previous()) {
if (tok->str() != "(" || !tok->astOperand1())
if (tok->str() != "(" || !tok->astOperand1() || tok->isCast())
continue;

const Function* function = nullptr;
Expand Down
11 changes: 11 additions & 0 deletions test/cfg/posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -1023,6 +1023,17 @@ void nullPointer(char *p, int fd, pthread_mutex_t mutex)
pthread_mutex_unlock(NULL);
}

void* f_returns_NULL(void*)
{
return NULL;
}

void nullPointer_pthread_create() // #12396
{
pthread_t thread;
pthread_create(&thread, NULL, (void* (*)(void*))f_returns_NULL, NULL);
}

void memleak_getaddrinfo()
{
//TODO: nothing to report yet, see http://sourceforge.net/p/cppcheck/discussion/general/thread/d9737d5d/
Expand Down

0 comments on commit 2921ba6

Please sign in to comment.