bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

localtime-buffer: Avoid endless recursion in localtime and gmtime


From: Bruno Haible
Subject: localtime-buffer: Avoid endless recursion in localtime and gmtime
Date: Thu, 13 Dec 2018 12:12:00 +0100
User-agent: KMail/5.1.3 (Linux/4.4.0-138-generic; KDE/5.18.0; x86_64; ; )

When running the gnulib unit tests in sed-4.5.48-58eb on Cygwin, I see
a crash of the test-gettimeofday.exe program. It is caused by endless
recursion: rpl_localtime and rpl_gmtime are compiled into endless
recursions.

You don't see this endless recursion when using a regular Autoconf release.
But the sed-4.5.48-58eb snapshot is built with an Autoconf snapshot that
contains a bug: it reports

  checking whether we are cross compiling... yes

(instead of 'no'), and as a consequence

  checking whether gettimeofday clobbers localtime buffer... guessing yes

(instead of 'no'), and thus localtime-buffer.c compiles to non-empty code.
This code, which was meant to invoke the system's localtime and gmtime
functions, invokes the gnulib replacements because localtime-buffer.h
includes <time.h> (which in this case is gnulib's time.h override).


This patch fixes the bug in gnulib. The bug in Autoconf is separate.


2018-12-13  Bruno Haible  <address@hidden>

        localtime-buffer: Avoid endless recursion in localtime and gmtime.
        * lib/localtime-buffer.c: Undefine localtime and gmtime before use.

diff --git a/lib/localtime-buffer.c b/lib/localtime-buffer.c
index 7f12ce6..a245e56 100644
--- a/lib/localtime-buffer.c
+++ b/lib/localtime-buffer.c
@@ -34,6 +34,7 @@ struct tm *localtime_buffer_addr = &tm_zero_buffer;
 
 struct tm *
 rpl_localtime (time_t const *timep)
+#undef localtime
 {
   struct tm *tm = localtime (timep);
 
@@ -46,6 +47,7 @@ rpl_localtime (time_t const *timep)
 /* Same as above, since gmtime and localtime use the same buffer.  */
 struct tm *
 rpl_gmtime (time_t const *timep)
+#undef gmtime
 {
   struct tm *tm = gmtime (timep);
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]