gm2
[Top][All Lists]
Advanced

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

Overflow in ABS should probably be catched by '-fsoft-check-all'


From: Runar Tenfjord
Subject: Overflow in ABS should probably be catched by '-fsoft-check-all'
Date: Fri, 11 Nov 2022 00:17:39 +0100

Consider the following program:

MODULE test;
FROM libc IMPORT printf;

VAR
    uval, i : CARDINAL;
    ival, j : INTEGER;
BEGIN
    printf("MAX(INTEGER) = %d\n", MAX(INTEGER));
    printf("MIN(INTEGER) = %d\n", MIN(INTEGER));
    ival := -2147483648;
    printf("ival = %d\n", ival);
    uval := ABS(ival);
    printf("uval = %u\n", uval);
    (* This fails, should probably work:
    uval := ABS(MIN(INTEGER));
    printf("uval = %u\n", uval);
    *)
    j := ABS(ival);
    printf("j = %d\n", j);
    (* ABS silently fails here due to the largest INTEGER is 2147483647 *)
END test.

As expected the ABS function fails due to the nature of two's complement
integers. Probably this should be cathed by the  '-fsoft-check-all' flag  as
this can create subtle errors on outside input data which is converted.
For me the  '-fsoft-check-all' gives Segmentation fault.

Best regards
Runar Tenfjord

reply via email to

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