diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-06-21 10:00:50 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-06-21 10:00:50 -0300 |
commit | 20a9853e0279903d255846108ffe320826dddcca (patch) | |
tree | 543c9c838a2cb2d30087125467643b07e6374607 | |
parent | 1d70708a784980bfeee142d3ed95f8df9e1b1a4a (diff) | |
download | lua-20a9853e0279903d255846108ffe320826dddcca.tar.gz lua-20a9853e0279903d255846108ffe320826dddcca.tar.bz2 lua-20a9853e0279903d255846108ffe320826dddcca.zip |
Cleaning macros in 'luaV_execute'
Ensure that operation macros, such as 'luai_numdiv' and 'luai_numidiv',
operate only on variables, or at most at 's2v(ra)'. ('s2v' is a nop, a
cast from pointer to pointer.)
-rw-r--r-- | lvm.c | 20 |
1 files changed, 14 insertions, 6 deletions
@@ -797,7 +797,8 @@ void luaV_finishOp (lua_State *L) { | |||
797 | #define op_arithfI_aux(L,v1,imm,fop,tm,flip) { \ | 797 | #define op_arithfI_aux(L,v1,imm,fop,tm,flip) { \ |
798 | lua_Number nb; \ | 798 | lua_Number nb; \ |
799 | if (tonumberns(v1, nb)) { \ | 799 | if (tonumberns(v1, nb)) { \ |
800 | setfltvalue(s2v(ra), fop(L, nb, cast_num(imm))); \ | 800 | lua_Number fimm = cast_num(imm); \ |
801 | setfltvalue(s2v(ra), fop(L, nb, fimm)); \ | ||
801 | } \ | 802 | } \ |
802 | else \ | 803 | else \ |
803 | Protect(luaT_trybiniTM(L, v1, imm, flip, ra, tm)); } | 804 | Protect(luaT_trybiniTM(L, v1, imm, flip, ra, tm)); } |
@@ -819,7 +820,8 @@ void luaV_finishOp (lua_State *L) { | |||
819 | TValue *v1 = vRB(i); \ | 820 | TValue *v1 = vRB(i); \ |
820 | int imm = GETARG_sC(i); \ | 821 | int imm = GETARG_sC(i); \ |
821 | if (ttisinteger(v1)) { \ | 822 | if (ttisinteger(v1)) { \ |
822 | setivalue(s2v(ra), iop(L, ivalue(v1), imm)); \ | 823 | lua_Integer iv1 = ivalue(v1); \ |
824 | setivalue(s2v(ra), iop(L, iv1, imm)); \ | ||
823 | } \ | 825 | } \ |
824 | else op_arithfI_aux(L, v1, imm, fop, tm, flip); } | 826 | else op_arithfI_aux(L, v1, imm, fop, tm, flip); } |
825 | 827 | ||
@@ -927,8 +929,11 @@ void luaV_finishOp (lua_State *L) { | |||
927 | #define op_order(L,opi,opf,other) { \ | 929 | #define op_order(L,opi,opf,other) { \ |
928 | int cond; \ | 930 | int cond; \ |
929 | TValue *rb = vRB(i); \ | 931 | TValue *rb = vRB(i); \ |
930 | if (ttisinteger(s2v(ra)) && ttisinteger(rb)) \ | 932 | if (ttisinteger(s2v(ra)) && ttisinteger(rb)) { \ |
931 | cond = opi(ivalue(s2v(ra)), ivalue(rb)); \ | 933 | lua_Integer ia = ivalue(s2v(ra)); \ |
934 | lua_Integer ib = ivalue(rb); \ | ||
935 | cond = opi(ia, ib); \ | ||
936 | } \ | ||
932 | else if (ttisnumber(s2v(ra)) && ttisnumber(rb)) \ | 937 | else if (ttisnumber(s2v(ra)) && ttisnumber(rb)) \ |
933 | cond = opf(s2v(ra), rb); \ | 938 | cond = opf(s2v(ra), rb); \ |
934 | else \ | 939 | else \ |
@@ -944,8 +949,11 @@ void luaV_finishOp (lua_State *L) { | |||
944 | int im = GETARG_sB(i); \ | 949 | int im = GETARG_sB(i); \ |
945 | if (ttisinteger(s2v(ra))) \ | 950 | if (ttisinteger(s2v(ra))) \ |
946 | cond = opi(ivalue(s2v(ra)), im); \ | 951 | cond = opi(ivalue(s2v(ra)), im); \ |
947 | else if (ttisfloat(s2v(ra))) \ | 952 | else if (ttisfloat(s2v(ra))) { \ |
948 | cond = opf(fltvalue(s2v(ra)), cast_num(im)); \ | 953 | lua_Number fa = fltvalue(s2v(ra)); \ |
954 | lua_Number fim = cast_num(im); \ | ||
955 | cond = opf(fa, fim); \ | ||
956 | } \ | ||
949 | else { \ | 957 | else { \ |
950 | int isf = GETARG_C(i); \ | 958 | int isf = GETARG_C(i); \ |
951 | Protect(cond = luaT_callorderiTM(L, s2v(ra), im, inv, isf, tm)); \ | 959 | Protect(cond = luaT_callorderiTM(L, s2v(ra), im, inv, isf, tm)); \ |