|
From: | Runar Tenfjord |
Subject: | Fwd: Overflow in 2nd argument in DEC procedure |
Date: | Sat, 5 Nov 2022 18:11:43 +0100 |
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
[Prev in Thread] | Current Thread | [Next in Thread] |