help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] Bash is corresponding weird towards invalid array index-


From: Greg Wooledge
Subject: Re: [Help-bash] Bash is corresponding weird towards invalid array index--Gao 2017.6.2
Date: Fri, 2 Jun 2017 09:49:09 -0400
User-agent: Mutt/1.4.2.3i

On Fri, Jun 02, 2017 at 08:15:15PM +0800, Zhiyuan Gao wrote:
> $array_1[0]=123
> $array_1[1]=456
> $array_1[2]=789

> $echo
> ${array_1[99999999999999999999999999999999999999999999999999999999999999999999]}
> 
> It actually returned 789!

Looks like integer overflow to me.  Array indices are 64-bit integers,
and you've exceeded that range.

imadev:~$ unset a
imadev:~$ a[2]=789
imadev:~$ echo "${a[2]} ${a[18446744073709551618]}"
789 789

You just got really (un)lucky with your string of 9s happening to map
back to 2, modulo 2^64.



reply via email to

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