[Commits] SDL: pthread: fix error code checks (thanks, Andreas!).

libsdl.org revision control commits-owner at libsdl.org
Sat Feb 17 20:58:33 PST 2018


details:   https://hg.libsdl.org/SDL/rev/ecddbd9fe6b5
changeset: 11881:ecddbd9fe6b5
user:      Ryan C. Gordon <icculus at icculus.org>
date:      Sat Feb 17 23:57:57 2018 -0500
description:
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.

diffstat:

 src/thread/pthread/SDL_syscond.c   |  2 +-
 src/thread/pthread/SDL_sysmutex.c  |  4 ++--
 src/thread/pthread/SDL_systhread.c |  4 ++--
 3 files changed, 5 insertions(+), 5 deletions(-)

diffs (54 lines):

diff -r 65634e8189f0 -r ecddbd9fe6b5 src/thread/pthread/SDL_syscond.c
--- a/src/thread/pthread/SDL_syscond.c	Sat Feb 17 20:18:48 2018 -0500
+++ b/src/thread/pthread/SDL_syscond.c	Sat Feb 17 23:57:57 2018 -0500
@@ -42,7 +42,7 @@
 
     cond = (SDL_cond *) SDL_malloc(sizeof(SDL_cond));
     if (cond) {
-        if (pthread_cond_init(&cond->cond, NULL) < 0) {
+        if (pthread_cond_init(&cond->cond, NULL) != 0) {
             SDL_SetError("pthread_cond_init() failed");
             SDL_free(cond);
             cond = NULL;
diff -r 65634e8189f0 -r ecddbd9fe6b5 src/thread/pthread/SDL_sysmutex.c
--- a/src/thread/pthread/SDL_sysmutex.c	Sat Feb 17 20:18:48 2018 -0500
+++ b/src/thread/pthread/SDL_sysmutex.c	Sat Feb 17 23:57:57 2018 -0500
@@ -105,7 +105,7 @@
         }
     }
 #else
-    if (pthread_mutex_lock(&mutex->id) < 0) {
+    if (pthread_mutex_lock(&mutex->id) != 0) {
         return SDL_SetError("pthread_mutex_lock() failed");
     }
 #endif
@@ -181,7 +181,7 @@
     }
 
 #else
-    if (pthread_mutex_unlock(&mutex->id) < 0) {
+    if (pthread_mutex_unlock(&mutex->id) != 0) {
         return SDL_SetError("pthread_mutex_unlock() failed");
     }
 #endif /* FAKE_RECURSIVE_MUTEX */
diff -r 65634e8189f0 -r ecddbd9fe6b5 src/thread/pthread/SDL_systhread.c
--- a/src/thread/pthread/SDL_systhread.c	Sat Feb 17 20:18:48 2018 -0500
+++ b/src/thread/pthread/SDL_systhread.c	Sat Feb 17 23:57:57 2018 -0500
@@ -212,7 +212,7 @@
     int policy;
     pthread_t thread = pthread_self();
 
-    if (pthread_getschedparam(thread, &policy, &sched) < 0) {
+    if (pthread_getschedparam(thread, &policy, &sched) != 0) {
         return SDL_SetError("pthread_getschedparam() failed");
     }
     if (priority == SDL_THREAD_PRIORITY_LOW) {
@@ -224,7 +224,7 @@
         int max_priority = sched_get_priority_max(policy);
         sched.sched_priority = (min_priority + (max_priority - min_priority) / 2);
     }
-    if (pthread_setschedparam(thread, policy, &sched) < 0) {
+    if (pthread_setschedparam(thread, policy, &sched) != 0) {
         return SDL_SetError("pthread_setschedparam() failed");
     }
     return 0;


More information about the commits mailing list