Date: Mon, 3 Jul 2023 21:11:58 -0600 From: Warner Losh <imp@bsdimp.com> To: "Pedro F. Giffuni" <pfg@freebsd.org> Cc: src-committers <src-committers@freebsd.org>, "<dev-commits-src-all@freebsd.org>" <dev-commits-src-all@freebsd.org>, "<dev-commits-src-main@freebsd.org>" <dev-commits-src-main@freebsd.org> Subject: Re: git: 4456846a1a0d - main - bin/date: Upgrade calculations Message-ID: <CANCZdfqMvf1QuS=fNQjRPe3YUbp1zPQW4aorh=VTRHk%2Bf_e8qg@mail.gmail.com> In-Reply-To: <202307040308.36438MTA093771@gitrepo.freebsd.org> References: <202307040308.36438MTA093771@gitrepo.freebsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
--0000000000000e782a05ffa0a639 Content-Type: text/plain; charset="UTF-8" This is a nope on armv7 and i386. So it has no effect there. DF got it wrong. These should likely be int64_t to avoid the overflow. No? Warner On Mon, Jul 3, 2023, 9:08 PM Pedro F. Giffuni <pfg@freebsd.org> wrote: > The branch main has been updated by pfg: > > URL: > https://cgit.FreeBSD.org/src/commit/?id=4456846a1a0d8cb6d0e6bae89f1134fa0a1af5cf > > commit 4456846a1a0d8cb6d0e6bae89f1134fa0a1af5cf > Author: Pedro F. Giffuni <pfg@FreeBSD.org> > AuthorDate: 2023-07-03 02:32:10 +0000 > Commit: Pedro F. Giffuni <pfg@FreeBSD.org> > CommitDate: 2023-07-04 03:08:01 +0000 > > bin/date: Upgrade calculations > > Use long instead of int for numerous calculations, fixing a number of > date calculation overflow issues. > > Obtained from: DragonflyBSD > Git log: 4238ce6f0c6df33ce677ae298b245c62cd60fb43 (only partial) > --- > bin/date/vary.c | 20 ++++++++++---------- > 1 file changed, 10 insertions(+), 10 deletions(-) > > diff --git a/bin/date/vary.c b/bin/date/vary.c > index 5f0123110ee3..6f3c59950ecf 100644 > --- a/bin/date/vary.c > +++ b/bin/date/vary.c > @@ -34,7 +34,7 @@ __FBSDID("$FreeBSD$"); > #include "vary.h" > > struct trans { > - int val; > + long val; > const char *str; > }; > > @@ -52,7 +52,7 @@ static struct trans trans_wday[] = { > }; > > static char digits[] = "0123456789"; > -static int adjhour(struct tm *, char, int, int); > +static int adjhour(struct tm *, char, long, int); > > static int > domktime(struct tm *t, char type) > @@ -125,7 +125,7 @@ daysinmonth(const struct tm *t) > > > static int > -adjyear(struct tm *t, char type, int val, int mk) > +adjyear(struct tm *t, char type, long val, int mk) > { > switch (type) { > case '+': > @@ -146,7 +146,7 @@ adjyear(struct tm *t, char type, int val, int mk) > } > > static int > -adjmon(struct tm *t, char type, int val, int istext, int mk) > +adjmon(struct tm *t, char type, long val, int istext, int mk) > { > int lmdays; > > @@ -206,7 +206,7 @@ adjmon(struct tm *t, char type, int val, int istext, > int mk) > } > > static int > -adjday(struct tm *t, char type, int val, int mk) > +adjday(struct tm *t, char type, long val, int mk) > { > int lmdays; > > @@ -250,7 +250,7 @@ adjday(struct tm *t, char type, int val, int mk) > } > > static int > -adjwday(struct tm *t, char type, int val, int istext, int mk) > +adjwday(struct tm *t, char type, long val, int istext, int mk) > { > if (val < 0) > return 0; > @@ -286,7 +286,7 @@ adjwday(struct tm *t, char type, int val, int istext, > int mk) > } > > static int > -adjhour(struct tm *t, char type, int val, int mk) > +adjhour(struct tm *t, char type, long val, int mk) > { > if (val < 0) > return 0; > @@ -331,7 +331,7 @@ adjhour(struct tm *t, char type, int val, int mk) > } > > static int > -adjmin(struct tm *t, char type, int val, int mk) > +adjmin(struct tm *t, char type, long val, int mk) > { > if (val < 0) > return 0; > @@ -372,7 +372,7 @@ adjmin(struct tm *t, char type, int val, int mk) > } > > static int > -adjsec(struct tm *t, char type, int val, int mk) > +adjsec(struct tm *t, char type, long val, int mk) > { > if (val < 0) > return 0; > @@ -419,7 +419,7 @@ vary_apply(const struct vary *v, struct tm *t) > char which; > char *arg; > size_t len; > - int val; > + long val; > > for (; v; v = v->next) { > type = *v->arg; > --0000000000000e782a05ffa0a639 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"auto">This is a nope on armv7 and i386. So it has no effect the= re. DF got it wrong. These should likely be int64_t to avoid the overflow. = No?<div dir=3D"auto"><br></div><div dir=3D"auto">Warner</div></div><br><div= class=3D"gmail_quote"><div dir=3D"ltr" class=3D"gmail_attr">On Mon, Jul 3,= 2023, 9:08 PM Pedro F. Giffuni <<a href=3D"mailto:pfg@freebsd.org">pfg@= freebsd.org</a>> wrote:<br></div><blockquote class=3D"gmail_quote" style= =3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">The bran= ch main has been updated by pfg:<br> <br> URL: <a href=3D"https://cgit.FreeBSD.org/src/commit/?id=3D4456846a1a0d8cb6d= 0e6bae89f1134fa0a1af5cf" rel=3D"noreferrer noreferrer" target=3D"_blank">ht= tps://cgit.FreeBSD.org/src/commit/?id=3D4456846a1a0d8cb6d0e6bae89f1134fa0a1= af5cf</a><br> <br> commit 4456846a1a0d8cb6d0e6bae89f1134fa0a1af5cf<br> Author:=C2=A0 =C2=A0 =C2=A0Pedro F. Giffuni <pfg@FreeBSD.org><br> AuthorDate: 2023-07-03 02:32:10 +0000<br> Commit:=C2=A0 =C2=A0 =C2=A0Pedro F. Giffuni <pfg@FreeBSD.org><br> CommitDate: 2023-07-04 03:08:01 +0000<br> <br> =C2=A0 =C2=A0 bin/date: Upgrade calculations<br> <br> =C2=A0 =C2=A0 Use long instead of int for numerous calculations, fixing a n= umber of<br> =C2=A0 =C2=A0 date calculation overflow issues.<br> <br> =C2=A0 =C2=A0 Obtained from:=C2=A0 DragonflyBSD<br> =C2=A0 =C2=A0 Git log:=C2=A0 =C2=A0 =C2=A0 =C2=A0 4238ce6f0c6df33ce677ae298= b245c62cd60fb43 (only partial)<br> ---<br> =C2=A0bin/date/vary.c | 20 ++++++++++----------<br> =C2=A01 file changed, 10 insertions(+), 10 deletions(-)<br> <br> diff --git a/bin/date/vary.c b/bin/date/vary.c<br> index 5f0123110ee3..6f3c59950ecf 100644<br> --- a/bin/date/vary.c<br> +++ b/bin/date/vary.c<br> @@ -34,7 +34,7 @@ __FBSDID("$FreeBSD$");<br> =C2=A0#include "vary.h"<br> <br> =C2=A0struct trans {<br> -=C2=A0 int val;<br> +=C2=A0 long val;<br> =C2=A0 =C2=A0const char *str;<br> =C2=A0};<br> <br> @@ -52,7 +52,7 @@ static struct trans trans_wday[] =3D {<br> =C2=A0};<br> <br> =C2=A0static char digits[] =3D "0123456789";<br> -static int adjhour(struct tm *, char, int, int);<br> +static int adjhour(struct tm *, char, long, int);<br> <br> =C2=A0static int<br> =C2=A0domktime(struct tm *t, char type)<br> @@ -125,7 +125,7 @@ daysinmonth(const struct tm *t)<br> <br> <br> =C2=A0static int<br> -adjyear(struct tm *t, char type, int val, int mk)<br> +adjyear(struct tm *t, char type, long val, int mk)<br> =C2=A0{<br> =C2=A0 =C2=A0switch (type) {<br> =C2=A0 =C2=A0 =C2=A0case '+':<br> @@ -146,7 +146,7 @@ adjyear(struct tm *t, char type, int val, int mk)<br> =C2=A0}<br> <br> =C2=A0static int<br> -adjmon(struct tm *t, char type, int val, int istext, int mk)<br> +adjmon(struct tm *t, char type, long val, int istext, int mk)<br> =C2=A0{<br> =C2=A0 =C2=A0int lmdays;<br> <br> @@ -206,7 +206,7 @@ adjmon(struct tm *t, char type, int val, int istext, in= t mk)<br> =C2=A0}<br> <br> =C2=A0static int<br> -adjday(struct tm *t, char type, int val, int mk)<br> +adjday(struct tm *t, char type, long val, int mk)<br> =C2=A0{<br> =C2=A0 =C2=A0int lmdays;<br> <br> @@ -250,7 +250,7 @@ adjday(struct tm *t, char type, int val, int mk)<br> =C2=A0}<br> <br> =C2=A0static int<br> -adjwday(struct tm *t, char type, int val, int istext, int mk)<br> +adjwday(struct tm *t, char type, long val, int istext, int mk)<br> =C2=A0{<br> =C2=A0 =C2=A0if (val < 0)<br> =C2=A0 =C2=A0 =C2=A0return 0;<br> @@ -286,7 +286,7 @@ adjwday(struct tm *t, char type, int val, int istext, i= nt mk)<br> =C2=A0}<br> <br> =C2=A0static int<br> -adjhour(struct tm *t, char type, int val, int mk)<br> +adjhour(struct tm *t, char type, long val, int mk)<br> =C2=A0{<br> =C2=A0 =C2=A0if (val < 0)<br> =C2=A0 =C2=A0 =C2=A0return 0;<br> @@ -331,7 +331,7 @@ adjhour(struct tm *t, char type, int val, int mk)<br> =C2=A0}<br> <br> =C2=A0static int<br> -adjmin(struct tm *t, char type, int val, int mk)<br> +adjmin(struct tm *t, char type, long val, int mk)<br> =C2=A0{<br> =C2=A0 =C2=A0if (val < 0)<br> =C2=A0 =C2=A0 =C2=A0return 0;<br> @@ -372,7 +372,7 @@ adjmin(struct tm *t, char type, int val, int mk)<br> =C2=A0}<br> <br> =C2=A0static int<br> -adjsec(struct tm *t, char type, int val, int mk)<br> +adjsec(struct tm *t, char type, long val, int mk)<br> =C2=A0{<br> =C2=A0 =C2=A0if (val < 0)<br> =C2=A0 =C2=A0 =C2=A0return 0;<br> @@ -419,7 +419,7 @@ vary_apply(const struct vary *v, struct tm *t)<br> =C2=A0 =C2=A0char which;<br> =C2=A0 =C2=A0char *arg;<br> =C2=A0 =C2=A0size_t len;<br> -=C2=A0 int val;<br> +=C2=A0 long val;<br> <br> =C2=A0 =C2=A0for (; v; v =3D v->next) {<br> =C2=A0 =C2=A0 =C2=A0type =3D *v->arg;<br> </blockquote></div> --0000000000000e782a05ffa0a639--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CANCZdfqMvf1QuS=fNQjRPe3YUbp1zPQW4aorh=VTRHk%2Bf_e8qg>