Sebastian 2018-07-21 17:52:12 +02:00 committed by GitHub
parent a44b4ba441
commit f862cf603f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 78 additions and 1 deletions

View File

@ -2928,6 +2928,56 @@ The function 'mktemp' is considered to be dangerous due to race conditions and s
</arg>
<warn severity="style" reason="Obsolescent" alternatives="pthread_attr_getstack"/>
</function>
<!-- int pthread_mutex_init(pthread_mutex_t *restrict mutex, const pthread_mutexattr_t *restrict attr); -->
<function name="pthread_mutex_init">
<noreturn>false</noreturn>
<returnValue type="int"/>
<arg nr="1">
<not-null/>
</arg>
<arg nr="2">
<!-- NULL is valid -->
</arg>
</function>
<!-- int pthread_mutex_destroy(pthread_mutex_t *mutex); -->
<function name="pthread_mutex_destroy">
<noreturn>false</noreturn>
<returnValue type="int"/>
<arg nr="1">
<not-null/>
<not-uninit/>
</arg>
</function>
<!-- int pthread_mutex_lock(pthread_mutex_t *mutex); -->
<function name="pthread_mutex_lock">
<noreturn>false</noreturn>
<leak-ignore/>
<returnValue type="int"/>
<arg nr="1">
<not-null/>
<not-uninit/>
</arg>
</function>
<!-- int pthread_mutex_trylock(pthread_mutex_t *mutex); -->
<function name="pthread_mutex_trylock">
<noreturn>false</noreturn>
<leak-ignore/>
<returnValue type="int"/>
<arg nr="1">
<not-null/>
<not-uninit/>
</arg>
</function>
<!-- int pthread_mutex_unlock(pthread_mutex_t *mutex); -->
<function name="pthread_mutex_unlock">
<noreturn>false</noreturn>
<leak-ignore/>
<returnValue type="int"/>
<arg nr="1">
<not-null/>
<not-uninit/>
</arg>
</function>
<!-- char *tempnam(const char *dir, const char *pfx); -->
<function name="tempnam">
<use-retval/>

View File

@ -18,6 +18,7 @@
#include <regex.h>
#include <time.h>
#include <unistd.h>
#include <pthread.h>
void bufferAccessOutOfBounds(int fd)
{
@ -54,7 +55,7 @@ void bufferAccessOutOfBounds(int fd)
gethostname(a, 6);
}
void nullPointer(char *p, int fd)
void nullPointer(char *p, int fd, pthread_mutex_t mutex)
{
// cppcheck-suppress ignoredReturnValue
isatty(0);
@ -88,6 +89,19 @@ void nullPointer(char *p, int fd)
// cppcheck-suppress strtokCalled
// cppcheck-suppress nullPointer
strtok(p, NULL);
// cppcheck-suppress nullPointer
pthread_mutex_init(NULL, NULL);
// Second argument can be NULL
pthread_mutex_init(&mutex, NULL);
// cppcheck-suppress nullPointer
pthread_mutex_destroy(NULL);
// cppcheck-suppress nullPointer
pthread_mutex_lock(NULL);
// cppcheck-suppress nullPointer
pthread_mutex_trylock(NULL);
// cppcheck-suppress nullPointer
pthread_mutex_unlock(NULL);
}
void memleak_getaddrinfo()
@ -207,6 +221,7 @@ void uninitvar(int fd)
int decimal, sign;
double d;
void *p;
pthread_mutex_t mutex;
// cppcheck-suppress uninitvar
write(x,"ab",2);
// TODO cppcheck-suppress uninitvar
@ -259,6 +274,18 @@ void uninitvar(int fd)
// cppcheck-suppress strtokCalled
// cppcheck-suppress uninitvar
strtok(strtok_arg1, ";");
// cppcheck-suppress uninitvar
pthread_mutex_lock(&mutex);
// cppcheck-suppress uninitvar
pthread_mutex_trylock(&mutex);
// cppcheck-suppress uninitvar
pthread_mutex_unlock(&mutex);
// 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);
pthread_mutex_unlock(&mutex);
}
void uninitvar_getcwd(void)