[newlib-cygwin] Cygwin: posix timers: fix error handling in public API

Corinna Vinschen corinna@sourceware.org
Tue Jan 22 15:38:00 GMT 2019


https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=de0ec284a3aeb31601383c507904ddaf755854f6

commit de0ec284a3aeb31601383c507904ddaf755854f6
Author: Corinna Vinschen <corinna@vinschen.de>
Date:   Tue Jan 22 16:37:15 2019 +0100

    Cygwin: posix timers: fix error handling in public API
    
    Signed-off-by: Corinna Vinschen <corinna@vinschen.de>

Diff:
---
 winsup/cygwin/posix_timer.cc | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/winsup/cygwin/posix_timer.cc b/winsup/cygwin/posix_timer.cc
index e969dcc..5f569b6 100644
--- a/winsup/cygwin/posix_timer.cc
+++ b/winsup/cygwin/posix_timer.cc
@@ -433,17 +433,20 @@ timer_create (clockid_t clock_id, struct sigevent *__restrict evp,
       if (CLOCKID_IS_PROCESS (clock_id) || CLOCKID_IS_THREAD (clock_id))
 	{
 	  set_errno (ENOTSUP);
-	  return -1;
+	  __leave;
 	}
 
       if (clock_id >= MAX_CLOCKS)
 	{
 	  set_errno (EINVAL);
-	  return -1;
+	  __leave;
 	}
 
       *timerid = (timer_t) cnew (timer_tracker, clock_id, evp);
-      ret = 0;
+      if (!*timerid)
+	__seterrno ();
+      else
+	ret = 0;
     }
   __except (EFAULT) {}
   __endtry
@@ -461,12 +464,15 @@ timer_gettime (timer_t timerid, struct itimerspec *ovalue)
       if (!tt->is_timer_tracker ())
 	{
 	  set_errno (EINVAL);
-	  return -1;
+	  __leave;
 	}
 
       ret = tt->gettime (ovalue, true);
       if (ret < 0)
-	set_errno (-ret);
+	{
+	  set_errno (-ret);
+	  ret = -1;
+	}
     }
   __except (EFAULT) {}
   __endtry
@@ -490,7 +496,10 @@ timer_settime (timer_t timerid, int flags,
 	}
       ret = tt->settime (flags, value, ovalue);
       if (ret < 0)
-	set_errno (-ret);
+	{
+	  set_errno (-ret);
+	  ret = -1;
+	}
     }
   __except (EFAULT) {}
   __endtry



More information about the Cygwin-cvs mailing list