Diff of /sem_timedwait.c [1beb00] .. [9e61bc]  Maximize  Restore

  Switch to side-by-side view

--- a/sem_timedwait.c
+++ b/sem_timedwait.c
@@ -137,6 +137,8 @@
   int result = 0;
   sem_t s = *sem;
 
+  pthread_testcancel();
+
   if (sem == NULL)
     {
       result = EINVAL;
@@ -157,11 +159,20 @@
 	  milliseconds = ptw32_relmillisecs (abstime);
 	}
 
-      pthread_testcancel();
-
       if ((result = pthread_mutex_lock (&s->lock)) == 0)
 	{
-	  int v = --s->value;
+	  int v;
+
+	  /* See sem_destroy.c
+	   */
+	  if (*sem == NULL)
+	    {
+	      (void) pthread_mutex_unlock (&s->lock);
+	      errno = EINVAL;
+	      return -1;
+	    }
+
+	  v = --s->value;
 	  (void) pthread_mutex_unlock (&s->lock);
 
 	  if (v < 0)
@@ -192,6 +203,13 @@
 
 	      if (!timedout && pthread_mutex_lock (&s->lock) == 0)
 	        {
+        	  if (*sem == NULL)
+        	    {
+        	      (void) pthread_mutex_unlock (&s->lock);
+        	      errno = EINVAL;
+        	      return -1;
+        	    }
+
 	          if (s->leftToUnblock > 0)
 	            {
 		      --s->leftToUnblock;

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks