Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #12396 FP nullPointer for pthread_create with function type cast #5927

Merged
merged 2 commits into from
Jan 31, 2024
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
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
Loading