Skip to content

Commit 37a06d2

Browse files
Fix #15113 FP nullPointer with pthread functions (cppcheck-opensource#8946)
1 parent e100161 commit 37a06d2

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

‎cfg/posix.cfg‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4638,7 +4638,7 @@ The function 'mktemp' is considered to be dangerous due to race conditions and s
46384638
<not-null/>
46394639
</arg>
46404640
<arg nr="2" direction="in">
4641-
<not-null/>
4641+
<not-uninit/>
46424642
</arg>
46434643
</function>
46444644
<function name="pthread_cond_destroy">
@@ -4658,7 +4658,6 @@ The function 'mktemp' is considered to be dangerous due to race conditions and s
46584658
<not-uninit/>
46594659
</arg>
46604660
<arg nr="2">
4661-
<not-null/>
46624661
<not-uninit/>
46634662
</arg>
46644663
</function>

‎test/cfg/posix.c‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1524,9 +1524,11 @@ void pthread_cond_timedwait_test(pthread_cond_t *cond, pthread_mutex_t *mutex, c
15241524

15251525
void pthread_cond_init_test(pthread_cond_t *cond, const pthread_condattr_t *attr)
15261526
{
1527-
// cppcheck-suppress nullPointer
15281527
(void)pthread_cond_init(cond, NULL);
15291528
(void)pthread_cond_init(cond, attr);
1529+
const pthread_condattr_t *uattr;
1530+
// cppcheck-suppress uninitvar
1531+
(void)pthread_cond_init(cond, uattr);
15301532
}
15311533

15321534
void pthread_cond_destroy_test(const pthread_cond_t *cond)
@@ -1540,6 +1542,12 @@ void pthread_cleanup_push_test(void (*routine)(void *), void *arg)
15401542
pthread_cleanup_pop(0);
15411543
}
15421544

1545+
void pthread_cleanup_push_test_NULL(void (*routine)(void *))
1546+
{
1547+
pthread_cleanup_push(routine, NULL);
1548+
pthread_cleanup_pop(0);
1549+
}
1550+
15431551
void pthread_mutexattr_init_test(pthread_mutexattr_t *attr)
15441552
{
15451553
(void)pthread_mutexattr_init(attr);
@@ -1606,4 +1614,4 @@ void pthread_define_test()
16061614
(void)rwlock;
16071615
PTHREAD_SCOPE_PROCESS;
16081616
PTHREAD_SCOPE_SYSTEM;
1609-
}
1617+
}

0 commit comments

Comments
 (0)