diff options
-rw-r--r-- | lstrlib.c | 7 |
1 files changed, 4 insertions, 3 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstrlib.c,v 1.104 2004/07/09 18:24:41 roberto Exp roberto $ | 2 | ** $Id: lstrlib.c,v 1.105 2004/08/06 17:35:38 roberto Exp roberto $ |
3 | ** Standard library for string operations and pattern-matching | 3 | ** Standard library for string operations and pattern-matching |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -110,8 +110,9 @@ static int str_byte (lua_State *L) { | |||
110 | sint32 posi = posrelat(luaL_optinteger(L, 2, 1), l); | 110 | sint32 posi = posrelat(luaL_optinteger(L, 2, 1), l); |
111 | sint32 pose = posrelat(luaL_optinteger(L, 3, posi), l); | 111 | sint32 pose = posrelat(luaL_optinteger(L, 3, posi), l); |
112 | int n, i; | 112 | int n, i; |
113 | if (!(0 < posi && posi <= pose && (size_t)pose <= l)) | 113 | if (posi <= 0) posi = 1; |
114 | return 0; /* index out of range; no answer */ | 114 | if ((size_t)pose > l) pose = l; |
115 | if (posi > pose) return 0; /* empty interval; return no values */ | ||
115 | n = pose - posi + 1; | 116 | n = pose - posi + 1; |
116 | luaL_checkstack(L, n, "string slice too long"); | 117 | luaL_checkstack(L, n, "string slice too long"); |
117 | for (i=0; i<n; i++) | 118 | for (i=0; i<n; i++) |