Implicit assumptions (was: Re: Some fun with -O2)
Walter von Entferndt
walter.von.entferndt at posteo.net
Fri Jan 15 18:45:29 UTC 2021
Dear Sirs,
the behaviour on signed overflow is /explicitely undefined/ in C...
I'd like to kindly suggest to fix the bug instead of fiddling around with
compiler switches to compile a buggy program:
--- check_mktime.c.patch ---
--- check_mktime.c.orig 2021-01-15 03:19:33.962253000 +0100
+++ check_mktime.c 2021-01-15 04:04:22.291014000 +0100
@@ -1,13 +1,16 @@
/* Test program from Paul Eggert (eggert at twinsun.com)
and Tony Leneis (tony at plaza.ds.adp.com). */
# include <sys/time.h>
+# include <sys/param.h> /* NBBY: #bits of a byte */
# include <time.h>
# include <unistd.h>
+# include <stdlib.h>
/* Work around redefinition to rpl_putenv by other config tests. */
#undef putenv
-static time_t time_t_max;
+const time_t t0 = (time_t) 1 << (NBBY*sizeof t0 - 2); /* unused elsewhere */
+static const time_t time_t_max = t0|(t0 - 1);
/* Values we'll use to set the TZ environment variable. */
static const char *const tz_strings[] = {
@@ -106,9 +109,6 @@
time_t t, delta;
int i, j;
- for (time_t_max = 1; 0 < time_t_max; time_t_max *= 2)
- continue;
- time_t_max--;
delta = time_t_max / 997; /* a suitable prime number */
for (i = 0; i < N_STRINGS; i++)
{
--
=|o) "Stell' Dir vor es geht und keiner kriegt's hin." (Wolfgang Neuss)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: check_mktime.c.patch
Type: text/x-patch
Size: 971 bytes
Desc: not available
URL: <http://lists.freebsd.org/pipermail/freebsd-hackers/attachments/20210115/6d281953/attachment.bin>
More information about the freebsd-hackers
mailing list