lua-users home
lua-l archive

Re: Lua 5.1.3 bug in string.byte

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


Interesting, compare -
#lua -e "for i=5,-10,-1 do print(i, string.sub('abc', i)) end"
5
4
3 c
2 bc
1 abc
0 abc
-1 c
-2 bc
-3 abc
-4 abc
-5 abc
-6 abc
-7 abc
-8 abc
-9 abc
-10 abc
and
#lua -e "for i=5,-10,-1 do print(i, string.byte('abc', i, 3)) end"
5
4
3 99
2 98 99
1 97 98 99
0 97 98 99
-1 99
-2 98 99
-3 97 98 99
-4 97 98 99
-5 97 98 99
-6 97 98 99
-7 97 98 99
-8 97 98 99
-9 97 98 99
-10 97 98 99
On Tue, Jun 3, 2008 at 9:37 AM, Mike Pall <mikelu-0806@mike.de> wrote:
> The range check logic in string.byte is broken:
>
> $ lua -e 'for i=5,-10,-1 do print(i, string.byte("abc", i)) end'
> 5
> 4
> 3 99
> 2 98
> 1 97
> 0
> -1 99
> -2 98
> -3 97
> -4
> -5 97 98 99 <--- Unexpected results for -#str-2 and lower
> -6 97 98
> -7 97
> -8
> -9 97 98 99
> -10 97 98 99
>
> --Mike
>
-- 
David Burgess

AltStyle によって変換されたページ (->オリジナル) /