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: dualbus
Subject: Re: [Help-bash] Bash is corresponding weird towards invalid array index--Gao 2017.6.2
Date: Fri, 2 Jun 2017 08:56:29 -0500
User-agent: NeoMutt/20170113 (1.7.2)

On Fri, Jun 02, 2017 at 09:49:09AM -0400, Greg Wooledge wrote:
[...]
> > It actually returned 789!
> 
> Looks like integer overflow to me. Array indices are 64-bit integers,
> and you've exceeded that range.

>From the bash manual:

    ARITHMETIC EVALUATION

    The shell allows arithmetic expressions to be evaluated, under
    certain circumstances (see the let and declare builtin commands, the
    (( compound command, and Arithmetic Expansion). Evaluation is done
    in fixed-width integers with no check for overflow, though division
    by 0 is trapped and flagged as an error. The operators and their
    precedence, associativity, and values are the same as in the C
    language. The following list of operators is grouped into levels of
    equal-precedence operators. The levels are listed in order of
    decreasing precedence.

So you have to ensure your indices don't overflow.

-- 
Eduardo Bustamante
https://dualbus.me/



reply via email to

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