Skip to content

Commit 6f6ede7

Browse files
Fix #12396 FP nullPointer for pthread_create with function type cast (#5927)
1 parent 5c59d86 commit 6f6ede7

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

lib/valueflow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7863,7 +7863,7 @@ static void setFunctionReturnValue(const Function* f, Token* tok, ValueFlow::Val
78637863
static void valueFlowFunctionReturn(TokenList &tokenlist, ErrorLogger *errorLogger, const Settings& settings)
78647864
{
78657865
for (Token *tok = tokenlist.back(); tok; tok = tok->previous()) {
7866-
if (tok->str() != "(" || !tok->astOperand1())
7866+
if (tok->str() != "(" || !tok->astOperand1() || tok->isCast())
78677867
continue;
78687868

78697869
const Function* function = nullptr;

test/cfg/posix.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,6 +1023,17 @@ void nullPointer(char *p, int fd, pthread_mutex_t mutex)
10231023
pthread_mutex_unlock(NULL);
10241024
}
10251025

1026+
void* f_returns_NULL(void* arg)
1027+
{
1028+
return NULL;
1029+
}
1030+
1031+
void nullPointer_pthread_create() // #12396
1032+
{
1033+
pthread_t thread;
1034+
pthread_create(&thread, NULL, (void* (*)(void*))f_returns_NULL, NULL);
1035+
}
1036+
10261037
void memleak_getaddrinfo()
10271038
{
10281039
//TODO: nothing to report yet, see http://sourceforge.net/p/cppcheck/discussion/general/thread/d9737d5d/

0 commit comments

Comments
 (0)