瀏覽代碼

BUG: `strfind' gets wrong subject length when there is an offset

Roberto Ierusalimschy 25 年之前
父節點
當前提交
fe5c37ae95
共有 2 個文件被更改,包括 7 次插入2 次删除
  1. 5 0
      bugs
  2. 2 2
      lstrlib.c

+ 5 - 0
bugs

@@ -170,3 +170,8 @@ in the following platforms:
 * IRIX	  - cc, cc-purify
 * Windows - Visual C++ (.c e .cpp, warning level=4)
 
+
+** lstrlib.c
+Tue May  2 15:27:58 EST 2000
+>> `strfind' gets wrong subject length when there is an offset
+(by Jon Kleiser; since 4.0a)

+ 2 - 2
lstrlib.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lstrlib.c,v 1.40 2000/02/08 16:34:31 roberto Exp roberto $
+** $Id: lstrlib.c,v 1.41 2000/03/03 14:58:26 roberto Exp roberto $
 ** Standard library for string operations and pattern-matching
 ** See Copyright Notice in lua.h
 */
@@ -405,7 +405,7 @@ static void str_find (lua_State *L) {
   luaL_arg_check(L, 0 <= init && init <= l1, 3, "out of range");
   if (lua_getparam(L, 4) != LUA_NOOBJECT ||
       strpbrk(p, SPECIALS) == NULL) {  /* no special characters? */
-    const char *s2 = memfind(s+init, l1, p, l2);
+    const char *s2 = memfind(s+init, l1-init, p, l2);
     if (s2) {
       lua_pushnumber(L, s2-s+1);
       lua_pushnumber(L, s2-s+l2);