aboutsummaryrefslogtreecommitdiff
path: root/lstrlib.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-06-12 11:37:18 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-06-12 11:37:18 -0300
commit094880ef9ee5ef88d4298c6665f96ab233e460a5 (patch)
tree2e9a5210236874bd1b0b71fca4fe72aea234192e /lstrlib.c
parent1de5587184eb2d8d9f379c661f77f7e450764894 (diff)
downloadlua-094880ef9ee5ef88d4298c6665f96ab233e460a5.tar.gz
lua-094880ef9ee5ef88d4298c6665f96ab233e460a5.tar.bz2
lua-094880ef9ee5ef88d4298c6665f96ab233e460a5.zip
details
Diffstat (limited to 'lstrlib.c')
-rw-r--r--lstrlib.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/lstrlib.c b/lstrlib.c
index 5935d826..9d03a85e 100644
--- a/lstrlib.c
+++ b/lstrlib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstrlib.c,v 1.43 2000/05/24 13:54:49 roberto Exp roberto $ 2** $Id: lstrlib.c,v 1.44 2000/06/12 13:52:05 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*/
@@ -380,8 +380,10 @@ static const char *match (lua_State *L, const char *s, const char *p,
380 380
381 381
382 382
383static const char *memfind (const char *s1, long l1, const char *s2, long l2) { 383static const char *lmemfind (const char *s1, size_t l1,
384 if (l2 == 0) return s1; /* empty strings are everywhere ;-) */ 384 const char *s2, size_t l2) {
385 if (l2 == 0) return s1; /* empty strings are everywhere */
386 else if (l2 > l1) return NULL; /* avoids a negative `l1' */
385 else { 387 else {
386 const char *init; /* to search for a `*s2' inside `s1' */ 388 const char *init; /* to search for a `*s2' inside `s1' */
387 l2--; /* 1st char will be checked by `memchr' */ 389 l2--; /* 1st char will be checked by `memchr' */
@@ -409,7 +411,7 @@ static void str_find (lua_State *L) {
409 luaL_arg_check(L, 0 <= init && (size_t)init <= l1, 3, "out of range"); 411 luaL_arg_check(L, 0 <= init && (size_t)init <= l1, 3, "out of range");
410 if (lua_getparam(L, 4) != LUA_NOOBJECT || 412 if (lua_getparam(L, 4) != LUA_NOOBJECT ||
411 strpbrk(p, SPECIALS) == NULL) { /* no special characters? */ 413 strpbrk(p, SPECIALS) == NULL) { /* no special characters? */
412 const char *s2 = memfind(s+init, l1-init, p, l2); 414 const char *s2 = lmemfind(s+init, l1-init, p, l2);
413 if (s2) { 415 if (s2) {
414 lua_pushnumber(L, s2-s+1); 416 lua_pushnumber(L, s2-s+1);
415 lua_pushnumber(L, s2-s+l2); 417 lua_pushnumber(L, s2-s+l2);