From 2921ba698c72bd9415c5ee88319f898f24f0e585 Mon Sep 17 00:00:00 2001 From: chrchr Date: Wed, 31 Jan 2024 12:47:47 +0100 Subject: [PATCH] Fix #12396 FP nullPointer for pthread_create with function type cast --- lib/valueflow.cpp | 2 +- test/cfg/posix.c | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index b7865d78b1c..1ab6d42205b 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -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; diff --git a/test/cfg/posix.c b/test/cfg/posix.c index 5d696a5ba04..eaab9683d63 100644 --- a/test/cfg/posix.c +++ b/test/cfg/posix.c @@ -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/