From f310e8d951acfdbcacc56501e39c2e26caf152ae Mon Sep 17 00:00:00 2001 From: Jeff Johnston Date: Mon, 2 May 2016 16:11:26 -0400 Subject: [PATCH] Always assign return value to passed pointer in time function. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- newlib/libc/time/time.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/newlib/libc/time/time.c b/newlib/libc/time/time.c index 2506388f6..9de71d457 100644 --- a/newlib/libc/time/time.c +++ b/newlib/libc/time/time.c @@ -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; }