From 0f037c78525bfb7df49de8338826e15137859b1d Mon Sep 17 00:00:00 2001 From: Sascha Wildner Date: Fri, 19 Jan 2018 09:55:59 +0100 Subject: [PATCH] libthread_xu: Fix issues detected by gcc80. The changes to all deal with -Wnonnull-compare warnings, which are issued when a function has a NULL check for a parameter that at the same time is marked with __attribute__((nonnull(...))), aka __nonnull(...). Such __nonnull() decoration only ever catches those cases where NULL is passed directly to the function, but not any more indirect ways. What makes matters worse is that in higher optimization levels (-O >= 2), GCC will happily optimize out any NULL checks within the function for these parameters. This means that __nonnull() is generally inferior to a direct NULL check in the function itself and if we have both, which newer GCCs warn about with -Wnonnull-compare (that is part of -Wall), we should remove the __nonnull(). This commit does that for all parameters which our libthread_xu checks directly in the function. What remains are __nonnull() for parameters which are _not_ checked in the functions, to at least catch cases where NULL is passed directly. We should think about adding real checks for those parameters too. While here, add a "/* FALLTHROUGH */" comment in thr_printf.c which fixes a -Wimplicit-fallthrough warning. --- include/pthread.h | 88 ++++++++++++++++-------------------- lib/libthread_xu/thread/thr_printf.c | 1 + 2 files changed, 39 insertions(+), 50 deletions(-) diff --git a/include/pthread.h b/include/pthread.h index 12fb145979..991ecaa976 100644 --- a/include/pthread.h +++ b/include/pthread.h @@ -137,27 +137,24 @@ enum pthread_mutextype { */ __BEGIN_DECLS int pthread_atfork(void (*)(void), void (*)(void), void (*)(void)); -int pthread_attr_destroy(pthread_attr_t *) __nonnull(1); +int pthread_attr_destroy(pthread_attr_t *); int pthread_attr_getguardsize(const pthread_attr_t * __restrict, size_t *); int pthread_attr_getstack(const pthread_attr_t * __restrict, - void ** __restrict, size_t * __restrict) - __nonnull(1) __nonnull(2) __nonnull(3); -int pthread_attr_getstacksize(const pthread_attr_t *, size_t *) - __nonnull(1) __nonnull(2); + void ** __restrict, size_t * __restrict); +int pthread_attr_getstacksize(const pthread_attr_t *, size_t *); #if __BSD_VISIBLE || (__POSIX_VISIBLE && __POSIX_VISIBLE < 200809) int pthread_attr_getstackaddr(const pthread_attr_t *, void **); #endif -int pthread_attr_getdetachstate(const pthread_attr_t *, int *) - __nonnull(1) __nonnull(2); +int pthread_attr_getdetachstate(const pthread_attr_t *, int *); int pthread_attr_init(pthread_attr_t *) __nonnull(1); -int pthread_attr_setguardsize(pthread_attr_t *, size_t) __nonnull(1); +int pthread_attr_setguardsize(pthread_attr_t *, size_t); #if __BSD_VISIBLE || (__POSIX_VISIBLE && __POSIX_VISIBLE < 200809) int pthread_attr_setstackaddr(pthread_attr_t *, void *); #endif -int pthread_attr_setstacksize(pthread_attr_t *, size_t) __nonnull(1); -int pthread_attr_setstack(pthread_attr_t *, void *, size_t) __nonnull(1); -int pthread_attr_setdetachstate(pthread_attr_t *, int) __nonnull(1); +int pthread_attr_setstacksize(pthread_attr_t *, size_t); +int pthread_attr_setstack(pthread_attr_t *, void *, size_t); +int pthread_attr_setdetachstate(pthread_attr_t *, int); int pthread_barrier_destroy(pthread_barrier_t *); int pthread_barrier_init(pthread_barrier_t *, @@ -165,30 +162,28 @@ int pthread_barrier_init(pthread_barrier_t *, int pthread_barrier_wait(pthread_barrier_t *); int pthread_barrierattr_destroy(pthread_barrierattr_t *); int pthread_barrierattr_getpshared(const pthread_barrierattr_t *, int *); -int pthread_barrierattr_init(pthread_barrierattr_t *) __nonnull(1); +int pthread_barrierattr_init(pthread_barrierattr_t *); int pthread_barrierattr_setpshared(pthread_barrierattr_t *, int); void pthread_cleanup_pop(int); void pthread_cleanup_push(void (*) (void *), void *); -int pthread_condattr_destroy(pthread_condattr_t *) __nonnull(1); +int pthread_condattr_destroy(pthread_condattr_t *); int pthread_condattr_getclock(const pthread_condattr_t *, clockid_t *) - __nonnull(1) __nonnull(2); + __nonnull(2); int pthread_condattr_getpshared(const pthread_condattr_t *, int *) - __nonnull(1) __nonnull(2); + __nonnull(2); int pthread_condattr_init(pthread_condattr_t *) __nonnull(1); -int pthread_condattr_setclock(pthread_condattr_t *, clockid_t) - __nonnull(1); -int pthread_condattr_setpshared(pthread_condattr_t *, int) __nonnull(1); +int pthread_condattr_setclock(pthread_condattr_t *, clockid_t); +int pthread_condattr_setpshared(pthread_condattr_t *, int); int pthread_cond_broadcast(pthread_cond_t *) __nonnull(1); -int pthread_cond_destroy(pthread_cond_t *) __nonnull(1); +int pthread_cond_destroy(pthread_cond_t *); int pthread_cond_init(pthread_cond_t *, const pthread_condattr_t *) __nonnull(1); int pthread_cond_signal(pthread_cond_t *) __nonnull(1); int pthread_cond_timedwait(pthread_cond_t *, pthread_mutex_t *, - const struct timespec *) - __nonnull(1) __nonnull(2) __nonnull(3); + const struct timespec *) __nonnull(2); int pthread_cond_wait(pthread_cond_t *, pthread_mutex_t *) __nonnull(1) __nonnull(2); @@ -204,25 +199,23 @@ int pthread_key_create(pthread_key_t *, void (*) (void *)) __nonnull(1); int pthread_key_delete(pthread_key_t); int pthread_mutexattr_init(pthread_mutexattr_t *) __nonnull(1); -int pthread_mutexattr_destroy(pthread_mutexattr_t *) __nonnull(1); +int pthread_mutexattr_destroy(pthread_mutexattr_t *); int pthread_mutexattr_getpshared(const pthread_mutexattr_t *, int *) - __nonnull(1) __nonnull(2); -int pthread_mutexattr_gettype(pthread_mutexattr_t *, int *) - __nonnull(1) __nonnull(2); -int pthread_mutexattr_setpshared(pthread_mutexattr_t *, int) __nonnull(1); -int pthread_mutexattr_settype(pthread_mutexattr_t *, int) __nonnull(1); -int pthread_mutex_destroy(pthread_mutex_t *) __nonnull(1); + __nonnull(2); +int pthread_mutexattr_gettype(pthread_mutexattr_t *, int *) __nonnull(2); +int pthread_mutexattr_setpshared(pthread_mutexattr_t *, int); +int pthread_mutexattr_settype(pthread_mutexattr_t *, int); +int pthread_mutex_destroy(pthread_mutex_t *); int pthread_mutex_init(pthread_mutex_t *, const pthread_mutexattr_t *) __nonnull(1); -int pthread_mutex_lock(pthread_mutex_t *) __nonnull(1); -int pthread_mutex_timedlock(pthread_mutex_t *, const struct timespec *) - __nonnull(1) __nonnull(2); +int pthread_mutex_lock(pthread_mutex_t *); +int pthread_mutex_timedlock(pthread_mutex_t *, const struct timespec *); int pthread_mutex_trylock(pthread_mutex_t *) __nonnull(1); -int pthread_mutex_unlock(pthread_mutex_t *) __nonnull(1); +int pthread_mutex_unlock(pthread_mutex_t *); int pthread_once(pthread_once_t *, void (*) (void)) __nonnull(1); -int pthread_rwlock_destroy(pthread_rwlock_t *) __nonnull(1); +int pthread_rwlock_destroy(pthread_rwlock_t *); int pthread_rwlock_init(pthread_rwlock_t *, const pthread_rwlockattr_t *) __nonnull(1); int pthread_rwlock_rdlock(pthread_rwlock_t *) __nonnull(1); @@ -230,15 +223,15 @@ int pthread_rwlock_timedrdlock(pthread_rwlock_t *, const struct timespec *) __nonnull(1) __nonnull(2); int pthread_rwlock_timedwrlock(pthread_rwlock_t *, const struct timespec *) __nonnull(1) __nonnull(2); -int pthread_rwlock_tryrdlock(pthread_rwlock_t *) __nonnull(1); -int pthread_rwlock_trywrlock(pthread_rwlock_t *) __nonnull(1); -int pthread_rwlock_unlock(pthread_rwlock_t *) __nonnull(1); +int pthread_rwlock_tryrdlock(pthread_rwlock_t *); +int pthread_rwlock_trywrlock(pthread_rwlock_t *); +int pthread_rwlock_unlock(pthread_rwlock_t *); int pthread_rwlock_wrlock(pthread_rwlock_t *) __nonnull(1); -int pthread_rwlockattr_destroy(pthread_rwlockattr_t *) __nonnull(1); +int pthread_rwlockattr_destroy(pthread_rwlockattr_t *); int pthread_rwlockattr_getpshared(const pthread_rwlockattr_t *, int *) __nonnull(1) __nonnull(2); -int pthread_rwlockattr_init(pthread_rwlockattr_t *) __nonnull(1); +int pthread_rwlockattr_init(pthread_rwlockattr_t *); int pthread_rwlockattr_setpshared(pthread_rwlockattr_t *, int) __nonnull(1); pthread_t pthread_self(void); @@ -271,19 +264,14 @@ int pthread_mutex_getprioceiling(pthread_mutex_t *, int *); int pthread_mutex_setprioceiling(pthread_mutex_t *, int, int *); int pthread_attr_getinheritsched(const pthread_attr_t *, int *); -int pthread_attr_getschedparam(const pthread_attr_t *, struct sched_param *) - __nonnull(1) __nonnull(2); -int pthread_attr_getschedpolicy(const pthread_attr_t *, int *) - __nonnull(1) __nonnull(2); -int pthread_attr_getscope(const pthread_attr_t *, int *) - __nonnull(1) __nonnull(2); +int pthread_attr_getschedparam(const pthread_attr_t *, struct sched_param *); +int pthread_attr_getschedpolicy(const pthread_attr_t *, int *); +int pthread_attr_getscope(const pthread_attr_t *, int *); int pthread_attr_setinheritsched(pthread_attr_t *, int); -int pthread_attr_setschedparam(pthread_attr_t *, const struct sched_param *) - __nonnull(1) __nonnull(2); -int pthread_attr_setschedpolicy(pthread_attr_t *, int) __nonnull(1); -int pthread_attr_setscope(pthread_attr_t *, int) __nonnull(1); -int pthread_getschedparam(pthread_t pthread, int *, struct sched_param *) - __nonnull(2) __nonnull(3); +int pthread_attr_setschedparam(pthread_attr_t *, const struct sched_param *); +int pthread_attr_setschedpolicy(pthread_attr_t *, int); +int pthread_attr_setscope(pthread_attr_t *, int); +int pthread_getschedparam(pthread_t pthread, int *, struct sched_param *); int pthread_setschedparam(pthread_t, int, const struct sched_param *) __nonnull(3); #if __XSI_VISIBLE diff --git a/lib/libthread_xu/thread/thr_printf.c b/lib/libthread_xu/thread/thr_printf.c index 7fd112311c..7dc13f27c6 100644 --- a/lib/libthread_xu/thread/thr_printf.c +++ b/lib/libthread_xu/thread/thr_printf.c @@ -84,6 +84,7 @@ next: c = *fmt++; goto next; case 'p': islong = 1; + /* FALLTHROUGH */ case 'd': case 'u': case 'x': -- 2.11.4.GIT