[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Negative table index
- From: Tom N Harris <telliamed@...>
- Date: Mon, 22 Dec 2014 15:15:02 -0500
On Monday, December 22, 2014 01:13:12 PM Roberto Ierusalimschy wrote:
> The expression 'math.maxinteger*2+1' evaluates to -1 (by the rules
> of arithmetic overflows) before the function is called. The calls
> then become
>
> table.move({"a","b","c"},1,3, -1,{})
> table.move(t,1,-1, -1,{})
>
I was incorrectly thinking that table indexes were unsigned. The issue then is
overlapping copies when the sign changes. It's not that the source is
negative, but that the destination wraps around. What about this check?
n = e - f;
luaL_argcheck(L, t+n >= t, 4, "destination index overflows");
for (i = 0; i <= n; i++)
(skipping the overlap check for brevity)
--
tom <telliamed@whoopdedo.org>