pthread: fix error code checks (thanks, Andreas!).
authorRyan C. Gordon <icculus@icculus.org>
Sat, 17 Feb 2018 23:57:57 -0500
changeset 11881ecddbd9fe6b5
parent 11880 65634e8189f0
child 11882 0ee27779b86f
pthread: fix error code checks (thanks, Andreas!).

Most pthread functions return 0 on success and non-zero on error, but those
errors might be positive or negative, so checking for return values in the
Unix style, where errors are less than zero, is a bug.

Fixes Bugzilla #4039.
src/thread/pthread/SDL_syscond.c
src/thread/pthread/SDL_sysmutex.c
src/thread/pthread/SDL_systhread.c
     1.1 --- a/src/thread/pthread/SDL_syscond.c	Sat Feb 17 20:18:48 2018 -0500
     1.2 +++ b/src/thread/pthread/SDL_syscond.c	Sat Feb 17 23:57:57 2018 -0500
     1.3 @@ -42,7 +42,7 @@
     1.4  
     1.5      cond = (SDL_cond *) SDL_malloc(sizeof(SDL_cond));
     1.6      if (cond) {
     1.7 -        if (pthread_cond_init(&cond->cond, NULL) < 0) {
     1.8 +        if (pthread_cond_init(&cond->cond, NULL) != 0) {
     1.9              SDL_SetError("pthread_cond_init() failed");
    1.10              SDL_free(cond);
    1.11              cond = NULL;
     2.1 --- a/src/thread/pthread/SDL_sysmutex.c	Sat Feb 17 20:18:48 2018 -0500
     2.2 +++ b/src/thread/pthread/SDL_sysmutex.c	Sat Feb 17 23:57:57 2018 -0500
     2.3 @@ -105,7 +105,7 @@
     2.4          }
     2.5      }
     2.6  #else
     2.7 -    if (pthread_mutex_lock(&mutex->id) < 0) {
     2.8 +    if (pthread_mutex_lock(&mutex->id) != 0) {
     2.9          return SDL_SetError("pthread_mutex_lock() failed");
    2.10      }
    2.11  #endif
    2.12 @@ -181,7 +181,7 @@
    2.13      }
    2.14  
    2.15  #else
    2.16 -    if (pthread_mutex_unlock(&mutex->id) < 0) {
    2.17 +    if (pthread_mutex_unlock(&mutex->id) != 0) {
    2.18          return SDL_SetError("pthread_mutex_unlock() failed");
    2.19      }
    2.20  #endif /* FAKE_RECURSIVE_MUTEX */
     3.1 --- a/src/thread/pthread/SDL_systhread.c	Sat Feb 17 20:18:48 2018 -0500
     3.2 +++ b/src/thread/pthread/SDL_systhread.c	Sat Feb 17 23:57:57 2018 -0500
     3.3 @@ -212,7 +212,7 @@
     3.4      int policy;
     3.5      pthread_t thread = pthread_self();
     3.6  
     3.7 -    if (pthread_getschedparam(thread, &policy, &sched) < 0) {
     3.8 +    if (pthread_getschedparam(thread, &policy, &sched) != 0) {
     3.9          return SDL_SetError("pthread_getschedparam() failed");
    3.10      }
    3.11      if (priority == SDL_THREAD_PRIORITY_LOW) {
    3.12 @@ -224,7 +224,7 @@
    3.13          int max_priority = sched_get_priority_max(policy);
    3.14          sched.sched_priority = (min_priority + (max_priority - min_priority) / 2);
    3.15      }
    3.16 -    if (pthread_setschedparam(thread, policy, &sched) < 0) {
    3.17 +    if (pthread_setschedparam(thread, policy, &sched) != 0) {
    3.18          return SDL_SetError("pthread_setschedparam() failed");
    3.19      }
    3.20      return 0;