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 authored Jan 31, 2024
1 parent 5c59d86 commit 6f6ede7
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* arg)
{
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 6f6ede7

Please sign in to comment.