]> sourceware.org Git - newlib-cygwin.git/commitdiff
Always assign return value to passed pointer in time function.
authorJeff Johnston <jjohnstn@redhat.com>
Mon, 2 May 2016 20:11:26 +0000 (16:11 -0400)
committerJeff Johnston <jjohnstn@redhat.com>
Mon, 2 May 2016 20:11:26 +0000 (16:11 -0400)
If the passed t pointer is not a null pointer, always assign the return
value to the object it points to, regardless of whether the return value
is an error.

This is what the GNU C Library does, and this is also the expected
behavior according to the latest draft of the C programming language
standard (C11 ISO/IEC 9899:201x WG14 N1570, dated 2011-04-12):

Signed-off-by: Benoît Thébaudeau <benoit@wsystem.com>
newlib/libc/time/time.c

index 2506388f6de9972ae5516fe1b7632417de3549c8..9de71d45789a6a4bbc21f1985c6bdd3920055eba 100644 (file)
@@ -43,11 +43,10 @@ _DEFUN (time, (t),
 {
   struct timeval now;
 
-  if (_gettimeofday_r (_REENT, &now, NULL) >= 0)
-    {
-      if (t)
-       *t = now.tv_sec;
-      return now.tv_sec;
-    }
-  return -1;
+  if (_gettimeofday_r (_REENT, &now, NULL) < 0)
+    now.tv_sec = (time_t) -1;
+
+  if (t)
+    *t = now.tv_sec;
+  return now.tv_sec;
 }
This page took 0.029819 seconds and 5 git commands to generate.