gm2
[Top][All Lists]
Advanced

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

Fwd: Overflow in 2nd argument in DEC procedure


From: Runar Tenfjord
Subject: Fwd: Overflow in 2nd argument in DEC procedure
Date: Sat, 5 Nov 2022 18:11:43 +0100

Excelent,

I forgot to mention this bug was caught by a assertion in connection
with a test suite. This is part of some date calculation, hennch the big
numbers. Days in milliseconds etc.

The testsuite was compiled with ' -fsoft-check-all' and therefore I
expected this to be catched before the assertion.

The original language has an L suffix in the constant and
the _expression_ expanded in size.

I do not find any bug tracker, so I guess it is OK just to post to
the mailing list any findings.

Best regards
Runar Tenfjord

On Sat, Nov 5, 2022 at 3:17 PM Gaius Mulley <gaiusmod2@gmail.com> wrote:
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]