This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
mktime.c fixes (part 3 of 6): DEBUG improvements and fixes
- From: Paul Eggert <eggert at CS dot UCLA dot EDU>
- To: libc-alpha at sources dot redhat dot com
- Date: 31 Dec 2003 00:39:33 -0800
- Subject: mktime.c fixes (part 3 of 6): DEBUG improvements and fixes
This patch adjusts mktime.c's DEBUG code to make it more useful and
fix some bugs; it doesn't affect production mktime at all.
2003-12-30 Paul Eggert <eggert@twinsun.com>
* time/mktime.c (check_result): Use less-confusing report format.
"long" -> "long int", as per usual GNU style.
(main): Likewise.
Don't loop if the iteration overflows time_t.
Allow a negative step in the iteration.
===================================================================
RCS file: RCS/mktime.c,v
retrieving revision 1.51.0.2
retrieving revision 1.51.0.3
diff -pu -r1.51.0.2 -r1.51.0.3
--- mktime.c 2003/12/31 05:38:51 1.51.0.2
+++ mktime.c 2003/12/31 05:59:01 1.51.0.3
@@ -408,10 +408,10 @@ check_result (time_t tk, struct tm tmk,
if (tk != tl || !lt || not_equal_tm (&tmk, lt))
{
printf ("mktime (");
- print_tm (&tmk);
- printf (")\nyields (");
print_tm (lt);
- printf (") == %ld, should be %ld\n", (long) tl, (long) tk);
+ printf (")\nyields (");
+ print_tm (&tmk);
+ printf (") == %ld, should be %ld\n", (long int) tk, (long int) tl);
return 1;
}
@@ -424,7 +424,7 @@ main (int argc, char **argv)
int status = 0;
struct tm tm, tmk, tml;
struct tm *lt;
- time_t tk, tl;
+ time_t tk, tl, tl1;
char trailer;
if ((argc == 3 || argc == 4)
@@ -446,7 +446,7 @@ main (int argc, char **argv)
tml = *lt;
lt = &tml;
}
- printf ("mktime returns %ld == ", (long) tl);
+ printf ("mktime returns %ld == ", (long int) tl);
print_tm (&tmk);
printf ("\n");
status = check_result (tl, tmk, tl, lt);
@@ -458,7 +458,7 @@ main (int argc, char **argv)
time_t to = atol (argv[3]);
if (argc == 4)
- for (tl = from; tl <= to; tl += by)
+ for (tl = from; by < 0 ? to <= tl : tl <= to; tl = tl1)
{
lt = localtime (&tl);
if (lt)
@@ -469,12 +469,15 @@ main (int argc, char **argv)
}
else
{
- printf ("localtime (%ld) yields 0\n", (long) tl);
+ printf ("localtime (%ld) yields 0\n", (long int) tl);
status = 1;
}
+ tl1 = tl + by;
+ if ((tl1 < tl) != (by < 0))
+ break;
}
else
- for (tl = from; tl <= to; tl += by)
+ for (tl = from; by < 0 ? to <= tl : tl <= to; tl = tl1)
{
/* Null benchmark. */
lt = localtime (&tl);
@@ -486,9 +489,12 @@ main (int argc, char **argv)
}
else
{
- printf ("localtime (%ld) yields 0\n", (long) tl);
+ printf ("localtime (%ld) yields 0\n", (long int) tl);
status = 1;
}
+ tl1 = tl + by;
+ if ((tl1 < tl) != (by < 0))
+ break;
}
}
else