aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2003-02-12 07:10:41 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2003-02-12 07:10:41 -0200
commit8f105d6b5987fa97c7344c95c128f064766ca8e7 (patch)
tree7dd643d3931e230afd44a6d8bdf28baf2dc63473
parent2fef8c772b5d9c175941d4c8a64dedf736567466 (diff)
downloadlua-8f105d6b5987fa97c7344c95c128f064766ca8e7.tar.gz
lua-8f105d6b5987fa97c7344c95c128f064766ca8e7.tar.bz2
lua-8f105d6b5987fa97c7344c95c128f064766ca8e7.zip
string.byte returns nil if index is out-of-range
-rw-r--r--lstrlib.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/lstrlib.c b/lstrlib.c
index f4d37620..d882a73d 100644
--- a/lstrlib.c
+++ b/lstrlib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstrlib.c,v 1.92 2002/12/04 17:38:31 roberto Exp roberto $ 2** $Id: lstrlib.c,v 1.93 2002/12/20 10:26:33 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*/
@@ -98,7 +98,8 @@ static int str_byte (lua_State *L) {
98 size_t l; 98 size_t l;
99 const char *s = luaL_checklstring(L, 1, &l); 99 const char *s = luaL_checklstring(L, 1, &l);
100 sint32 pos = posrelat(luaL_optlong(L, 2, 1), l); 100 sint32 pos = posrelat(luaL_optlong(L, 2, 1), l);
101 luaL_argcheck(L, 0 < pos && (size_t)(pos) <= l, 2, "out of range"); 101 if (pos <= 0 || (size_t)(pos) > l) /* index out of range? */
102 return 0; /* no answer */
102 lua_pushnumber(L, uchar(s[pos-1])); 103 lua_pushnumber(L, uchar(s[pos-1]));
103 return 1; 104 return 1;
104} 105}