瀏覽代碼

lua_equal also accepts out-of-range indices

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

+ 5 - 2
lapi.c

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: lapi.c,v 1.87 2000/08/14 19:10:14 roberto Exp roberto $
+** $Id: lapi.c,v 1.88 2000/08/28 17:57:04 roberto Exp roberto $
 ** Lua API
 ** Lua API
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -116,7 +116,10 @@ int lua_tag (lua_State *L, int index) {
 }
 }
 
 
 int lua_equal(lua_State *L, int index1, int index2) {
 int lua_equal(lua_State *L, int index1, int index2) {
-  return luaO_equalObj(Index(L, index1), Index(L, index2));
+  StkId o1 = Index(L, index1);
+  StkId o2 = Index(L, index2);
+  if (o1 >= L->top || o2 >= L->top) return 0;  /* index out-of-range */
+  else return luaO_equalObj(o1, o2);
 }
 }