This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Use TIME_T_MAX and TIME_T_MIN in tst-mktime2.c


GCC 5.3 compiles

for (time_t_max = 1; 0 < time_t_max; time_t_max *= 2)
    continue;

into an infinite loop with -Os.  We can copy TIME_T_MAX and TIME_T_MIN
from time/mktime.c.

Tested on x86-64.  OK for trunk?

H.J.
---
	[BZ #19466]
	* time/tst-mktime2.c (TYPE_SIGNED): New.
	(TYPE_MINIMUM): Likewise.
	(TYPE_MAXIMUM): Likewise.
	(TIME_T_MIN): Likewise.
	(TIME_T_MAX): Likewise.
	(do_test): Initialize time_t_max and time_t_min with TIME_T_MAX
	and TIME_T_MIN.
---
 time/tst-mktime2.c | 31 +++++++++++++++++++++++++------
 1 file changed, 25 insertions(+), 6 deletions(-)

diff --git a/time/tst-mktime2.c b/time/tst-mktime2.c
index bc7cc58..fd40ab7 100644
--- a/time/tst-mktime2.c
+++ b/time/tst-mktime2.c
@@ -5,6 +5,29 @@
 #include <stdlib.h>
 #include <unistd.h>
 
+/* True if the arithmetic type T is signed.  */
+#define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
+
+/* The maximum and minimum values for the integer type T.  These
+   macros have undefined behavior if T is signed and has padding bits.
+   If this is a problem for you, please let us know how to fix it for
+   your host.  */
+#define TYPE_MINIMUM(t) \
+  ((t) (! TYPE_SIGNED (t) \
+	? (t) 0 \
+	: ~ TYPE_MAXIMUM (t)))
+#define TYPE_MAXIMUM(t) \
+  ((t) (! TYPE_SIGNED (t) \
+	? (t) -1 \
+	: ((((t) 1 << (sizeof (t) * CHAR_BIT - 2)) - 1) * 2 + 1)))
+
+#ifndef TIME_T_MIN
+# define TIME_T_MIN TYPE_MINIMUM (time_t)
+#endif
+#ifndef TIME_T_MAX
+# define TIME_T_MAX TYPE_MAXIMUM (time_t)
+#endif
+
 static time_t time_t_max;
 static time_t time_t_min;
 
@@ -113,12 +136,8 @@ do_test (void)
      isn't worth using anyway.  */
   alarm (60);
 
-  for (time_t_max = 1; 0 < time_t_max; time_t_max *= 2)
-    continue;
-  time_t_max--;
-  if ((time_t) -1 < 0)
-    for (time_t_min = -1; (time_t) (time_t_min * 2) < 0; time_t_min *= 2)
-      continue;
+  time_t_max = TIME_T_MAX;
+  time_t_min = TIME_T_MIN;
   delta = time_t_max / 997; /* a suitable prime number */
   for (i = 0; i < N_STRINGS; i++)
     {
-- 
2.5.0


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]