Re: git: 4456846a1a0d - main - bin/date: Upgrade calculations

From: Warner Losh <imp_at_bsdimp.com>
Date: Tue, 04 Jul 2023 03:11:58 UTC
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;
>