gm2
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Overflow in 2nd argument in DEC procedure


From: Gaius Mulley
Subject: Re: Overflow in 2nd argument in DEC procedure
Date: Sat, 05 Nov 2022 14:17:55 +0000
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)

Runar Tenfjord <runar.tenfjord@gmail.com> writes:

> The following program create different results due to silent
> overflow in the 2nd argument in the DEC procedure:
>
>  MODULE test;
>  FROM libc IMPORT printf;
>
>  VAR
>      bigval : LONGCARD;
>      smallval : CARDINAL;
>  BEGIN
>      bigval := 5184000000;
>      smallval := 60;
>      DEC(bigval, 86400000 * smallval);
>      printf('d1 = %llu\n', bigval);
>      bigval := 5184000000;
>      DEC(bigval, 86400000 * 60);
>      printf('d2 = %llu\n', bigval);
>  END test.
>
> Is this expected behavior?

Hi Runar,

thanks for the bug report.  The second DEC behaves as expected (both Z
type constants 86400000 * 60 multiply to 5184000000 and thus bigval is
zero.  But the first DEC 2nd operand overflows - as you mention.  This
should (at the very least) be caught by:

$ gm2 -g -fsoft-check-all test.mod
$ ./a.out

and it should be detected without -fsoft-check-all as cardinal
datatype will overflow (on architectures where cardinal is 32 bits).

I'll hunt this bug down,

regards,
Gaius



reply via email to

[Prev in Thread] Current Thread [Next in Thread]