posix.cfg: Add `<use-retval/>` to pthread_mutex_trylock (#1959)

Ignoring the return value of pthread_mutex_trylock is always a bug.
There is no other way to check if the mutex is locked or not after the
call.
This commit is contained in:
Sebastian 2019-07-07 12:57:02 +02:00 committed by GitHub
parent c902c5f688
commit db43dcd601
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 3 deletions

View File

@ -3995,6 +3995,7 @@ The function 'mktemp' is considered to be dangerous due to race conditions and s
<noreturn>false</noreturn>
<leak-ignore/>
<returnValue type="int"/>
<use-retval/>
<arg nr="1" direction="inout">
<not-null/>
<not-uninit/>

View File

@ -139,7 +139,7 @@ void nullPointer(char *p, int fd, pthread_mutex_t mutex)
// cppcheck-suppress nullPointer
pthread_mutex_lock(NULL);
// cppcheck-suppress nullPointer
pthread_mutex_trylock(NULL);
(void)pthread_mutex_trylock(NULL);
// cppcheck-suppress nullPointer
pthread_mutex_unlock(NULL);
}
@ -344,13 +344,13 @@ void uninitvar(int fd)
// cppcheck-suppress uninitvar
pthread_mutex_lock(&mutex1);
// cppcheck-suppress uninitvar
pthread_mutex_trylock(&mutex2);
(void)pthread_mutex_trylock(&mutex2);
// cppcheck-suppress uninitvar
pthread_mutex_unlock(&mutex3);
// after initialization it must be OK to call lock, trylock and unlock for this mutex
pthread_mutex_init(&mutex, NULL);
pthread_mutex_lock(&mutex);
pthread_mutex_trylock(&mutex);
(void)pthread_mutex_trylock(&mutex);
pthread_mutex_unlock(&mutex);
}