bug-bash
[Top][All Lists]
Advanced

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

Bug#973620: bash: overflow on integer variables greater than 92233720368


From: Gioele Barabucci
Subject: Bug#973620: bash: overflow on integer variables greater than 9223372036854775807
Date: Mon, 15 Apr 2024 13:59:10 +0200
User-agent: Mozilla Thunderbird

Control: found -1 5.2.21-2
Control: tags -1 upstream
X-Debbugs-CC: bug-bash@gnu.org

On Mon, 2 Nov 2020 16:46:14 +0100 Antonio <antdev66@gmail.com> wrote:
Dear Maintainer,
recently while I was running some tests, I ran into this strange overflow:

$ declare -i n=9223372036854775800; for((i=0; i<15; ++i)); do echo "$i -> $n";
n+=1; done

0 -> 9223372036854775800
1 -> 9223372036854775801
2 -> 9223372036854775802
3 -> 9223372036854775803
4 -> 9223372036854775804
5 -> 9223372036854775805
6 -> 9223372036854775806
7 -> 9223372036854775807
8 -> -9223372036854775808
9 -> -9223372036854775807
10 -> -9223372036854775806
11 -> -9223372036854775805
12 -> -9223372036854775804
13 -> -9223372036854775803
14 -> -9223372036854775802

The integer handled by bash is obviously very large, but I believe
that in the event of an overflow it would be better to reset the
variable and issue an error flow warning, rather than remain silent.

Bash 5.2.21 is affected by this issue:

    $ declare -i n=$((2**63 - 2))
    $ for i in {1..4}; do echo "$i -> $n"; n+=1; done
    1 -> 9223372036854775806
    2 -> 9223372036854775807
    3 -> -9223372036854775808
    4 -> -9223372036854775807

    $ declare -i n=36893488147419103234; echo $?
    0
    $ echo $n
    2

Would it be possible to detect this overflow (or non-representable numbers, like in the second case) and warn about it?

Regards,

--
Gioele Barabucci



reply via email to

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