Browse Source

Reject negative getfenv()/setfenv() levels to prevent compiler warning.

Thanks to Sergey Kaplun. #1329
Mike Pall 8 tháng trước cách đây
mục cha
commit
9d777346bc
1 tập tin đã thay đổi với 4 bổ sung0 xóa
  1. 4 0
      src/lib_base.c

+ 4 - 0
src/lib_base.c

@@ -141,6 +141,8 @@ LJLIB_CF(getfenv)
   cTValue *o = L->base;
   cTValue *o = L->base;
   if (!(o < L->top && tvisfunc(o))) {
   if (!(o < L->top && tvisfunc(o))) {
     int level = lj_lib_optint(L, 1, 1);
     int level = lj_lib_optint(L, 1, 1);
+    if (level < 0)
+      lj_err_arg(L, 1, LJ_ERR_INVLVL);
     o = lj_debug_frame(L, level, &level);
     o = lj_debug_frame(L, level, &level);
     if (o == NULL)
     if (o == NULL)
       lj_err_arg(L, 1, LJ_ERR_INVLVL);
       lj_err_arg(L, 1, LJ_ERR_INVLVL);
@@ -162,6 +164,8 @@ LJLIB_CF(setfenv)
       setgcref(L->env, obj2gco(t));
       setgcref(L->env, obj2gco(t));
       return 0;
       return 0;
     }
     }
+    if (level < 0)
+      lj_err_arg(L, 1, LJ_ERR_INVLVL);
     o = lj_debug_frame(L, level, &level);
     o = lj_debug_frame(L, level, &level);
     if (o == NULL)
     if (o == NULL)
       lj_err_arg(L, 1, LJ_ERR_INVLVL);
       lj_err_arg(L, 1, LJ_ERR_INVLVL);