Skip site navigation (1)Skip section navigation (2)
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

[-- Attachment #1 --]
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;
>

[-- Attachment #2 --]
<div dir="auto">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?<div dir="auto"><br></div><div dir="auto">Warner</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Jul 3, 2023, 9:08 PM Pedro F. Giffuni &lt;<a href="mailto:pfg@freebsd.org">pfg@freebsd.org</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">The branch main has been updated by pfg:<br>
<br>
URL: <a href="https://cgit.FreeBSD.org/src/commit/?id=4456846a1a0d8cb6d0e6bae89f1134fa0a1af5cf" rel="noreferrer noreferrer" target="_blank">https://cgit.FreeBSD.org/src/commit/?id=4456846a1a0d8cb6d0e6bae89f1134fa0a1af5cf</a><br>;
<br>
commit 4456846a1a0d8cb6d0e6bae89f1134fa0a1af5cf<br>
Author:     Pedro F. Giffuni &lt;pfg@FreeBSD.org&gt;<br>
AuthorDate: 2023-07-03 02:32:10 +0000<br>
Commit:     Pedro F. Giffuni &lt;pfg@FreeBSD.org&gt;<br>
CommitDate: 2023-07-04 03:08:01 +0000<br>
<br>
    bin/date: Upgrade calculations<br>
<br>
    Use long instead of int for numerous calculations, fixing a number of<br>
    date calculation overflow issues.<br>
<br>
    Obtained from:  DragonflyBSD<br>
    Git log:        4238ce6f0c6df33ce677ae298b245c62cd60fb43 (only partial)<br>
---<br>
 bin/date/vary.c | 20 ++++++++++----------<br>
 1 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(&quot;$FreeBSD$&quot;);<br>
 #include &quot;vary.h&quot;<br>
<br>
 struct trans {<br>
-  int val;<br>
+  long val;<br>
   const char *str;<br>
 };<br>
<br>
@@ -52,7 +52,7 @@ static struct trans trans_wday[] = {<br>
 };<br>
<br>
 static char digits[] = &quot;0123456789&quot;;<br>
-static int adjhour(struct tm *, char, int, int);<br>
+static int adjhour(struct tm *, char, long, int);<br>
<br>
 static int<br>
 domktime(struct tm *t, char type)<br>
@@ -125,7 +125,7 @@ daysinmonth(const struct tm *t)<br>
<br>
<br>
 static int<br>
-adjyear(struct tm *t, char type, int val, int mk)<br>
+adjyear(struct tm *t, char type, long val, int mk)<br>
 {<br>
   switch (type) {<br>
     case &#39;+&#39;:<br>
@@ -146,7 +146,7 @@ adjyear(struct tm *t, char type, int val, int mk)<br>
 }<br>
<br>
 static 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>
 {<br>
   int lmdays;<br>
<br>
@@ -206,7 +206,7 @@ adjmon(struct tm *t, char type, int val, int istext, int mk)<br>
 }<br>
<br>
 static int<br>
-adjday(struct tm *t, char type, int val, int mk)<br>
+adjday(struct tm *t, char type, long val, int mk)<br>
 {<br>
   int lmdays;<br>
<br>
@@ -250,7 +250,7 @@ adjday(struct tm *t, char type, int val, int mk)<br>
 }<br>
<br>
 static 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>
 {<br>
   if (val &lt; 0)<br>
     return 0;<br>
@@ -286,7 +286,7 @@ adjwday(struct tm *t, char type, int val, int istext, int mk)<br>
 }<br>
<br>
 static int<br>
-adjhour(struct tm *t, char type, int val, int mk)<br>
+adjhour(struct tm *t, char type, long val, int mk)<br>
 {<br>
   if (val &lt; 0)<br>
     return 0;<br>
@@ -331,7 +331,7 @@ adjhour(struct tm *t, char type, int val, int mk)<br>
 }<br>
<br>
 static int<br>
-adjmin(struct tm *t, char type, int val, int mk)<br>
+adjmin(struct tm *t, char type, long val, int mk)<br>
 {<br>
   if (val &lt; 0)<br>
     return 0;<br>
@@ -372,7 +372,7 @@ adjmin(struct tm *t, char type, int val, int mk)<br>
 }<br>
<br>
 static int<br>
-adjsec(struct tm *t, char type, int val, int mk)<br>
+adjsec(struct tm *t, char type, long val, int mk)<br>
 {<br>
   if (val &lt; 0)<br>
     return 0;<br>
@@ -419,7 +419,7 @@ vary_apply(const struct vary *v, struct tm *t)<br>
   char which;<br>
   char *arg;<br>
   size_t len;<br>
-  int val;<br>
+  long val;<br>
<br>
   for (; v; v = v-&gt;next) {<br>
     type = *v-&gt;arg;<br>
</blockquote></div>

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CANCZdfqMvf1QuS=fNQjRPe3YUbp1zPQW4aorh=VTRHk%2Bf_e8qg>