bug-bash
[Top][All Lists]
Advanced

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

Re: +=() can be used to set illegal indices


From: Chet Ramey
Subject: Re: +=() can be used to set illegal indices
Date: Tue, 27 Jun 2023 18:12:01 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.12.0

On 6/27/23 10:30 AM, Emanuele Torre wrote:
If an indexed array has no available slots after its last index, +=()
will overflow the last index, and set into an illegal negative index,
effectively prepending values instead of appending them.

Thanks for the report. I think it's reasonable to check for overflow here,
and not to use the convention that negative subscripts count back from the
end.

I think if  INTMAX_MAX - last_index < elements_to_append  , bash should
just error (error similar to setting to a readonly variable).

It should be an assignment error similar to

a[-1]=value

to an empty array.

Chet

--
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/




reply via email to

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