Date: Fri, 15 Jan 2021 19:43:14 +0100 From: Walter von Entferndt <walter.von.entferndt@posteo.net> To: freebsd-hackers@freebsd.org Subject: Re: Implicit assumptions (was: Re: Some fun with -O2) Message-ID: <179047366.Z9jOzuS0a2@t450s.local.lan> In-Reply-To: <8D35ADAE-8904-4400-9DEB-7B274189BC30@yahoo.com> References: <mailman.29.1610625600.45116.freebsd-hackers@freebsd.org> <4842729.YNO7O01DYZ@t450s.local.lan> <8D35ADAE-8904-4400-9DEB-7B274189BC30@yahoo.com>
next in thread | previous in thread | raw e-mail | index | archive | help
This is a multi-part message in MIME format. --nextPart12097100.5MqMfjp4zD Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" 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@twinsun.com) and Tony Leneis (tony@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) --nextPart12097100.5MqMfjp4zD Content-Disposition: attachment; filename="check_mktime.c.patch" Content-Transfer-Encoding: 7Bit Content-Type: text/x-patch; charset="UTF-8"; name="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@twinsun.com) and Tony Leneis (tony@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++) { --nextPart12097100.5MqMfjp4zD--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?179047366.Z9jOzuS0a2>