bug-bash
[Top][All Lists]
Advanced

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

Issue with parameter expansion with array when index > 2^31


From: felix
Subject: Issue with parameter expansion with array when index > 2^31
Date: Thu, 05 Aug 2021 22:07:30 +0200

Configuration Information:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -g -O2 -Wno-parentheses -Wno-format-security
uname output: Linux medium 4.19.0-16-amd64 #1 SMP Debian 4.19.181-1 
(2021-03-19) x86_64 GNU/Linux
Machine Type: x86_64-pc-linux-gnu

Bash Version: 5.1
Patch Level: 8
Release Status: release

Description:
        parameter expansion don't work correctly with array when index become
        bigger than 31 bit value

Repeat-By:
        for ((i=(1<<31)-3;i<(1<<31)+4;i++)){ a[i]='foo bar';}
        declare -p a
        declare -a a=([2147483645]="foo bar" [2147483646 .. 3651]="foo bar")

        for i in ${!a[@]};do echo $i ${a[i]% *};done
        2147483645 foo
        2147483646 foo
        2147483647 foo
        2147483648
        2147483649
        2147483650
        2147483651

Fix:
Not a fix, but:
        paste -d\  <(printf %s\\n ${!a[@]}) <(printf %s\\n "${a[@]% *}")
        2147483645 foo
        2147483646 foo
        2147483647 foo
        2147483648 foo
        2147483649 foo
        2147483650 foo
        2147483651 foo




reply via email to

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