Avoid an assignment of values that overlap

The original code was like this, where t->u.ind.t and t->u.info overlap:

  t->u.ind.t = cast_byte((t->k == VLOCAL) ? t->u.var.ridx: t->u.info);
This commit is contained in:
Roberto Ierusalimschy 2026-02-09 13:44:27 -03:00
parent c6b4848238
commit b60e2bcd7c

View file

@ -827,7 +827,7 @@ void luaK_dischargevars (FuncState *fs, expdesc *e) {
} /* FALLTHROUGH */ } /* FALLTHROUGH */
case VLOCAL: { /* already in a register */ case VLOCAL: { /* already in a register */
int temp = e->u.var.ridx; int temp = e->u.var.ridx;
e->u.info = temp; /* (can't do a direct assignment; values overlap) */ e->u.info = temp; /* (avoid a direct assignment; values overlap) */
e->k = VNONRELOC; /* becomes a non-relocatable value */ e->k = VNONRELOC; /* becomes a non-relocatable value */
break; break;
} }
@ -1365,7 +1365,7 @@ void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k) {
luaK_exp2anyreg(fs, t); /* put it in a register */ luaK_exp2anyreg(fs, t); /* put it in a register */
if (t->k == VUPVAL) { if (t->k == VUPVAL) {
lu_byte temp = cast_byte(t->u.info); /* upvalue index */ lu_byte temp = cast_byte(t->u.info); /* upvalue index */
t->u.ind.t = temp; /* (can't do a direct assignment; values overlap) */ t->u.ind.t = temp; /* (avoid a direct assignment; values overlap) */
lua_assert(isKstr(fs, k)); lua_assert(isKstr(fs, k));
fillidxk(t, k->u.info, VINDEXUP); /* literal short string */ fillidxk(t, k->u.info, VINDEXUP); /* literal short string */
} }
@ -1373,12 +1373,13 @@ void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k) {
int kreg = luaK_exp2anyreg(fs, k); /* put key in some register */ int kreg = luaK_exp2anyreg(fs, k); /* put key in some register */
lu_byte vreg = cast_byte(t->u.var.ridx); /* register with vararg param. */ lu_byte vreg = cast_byte(t->u.var.ridx); /* register with vararg param. */
lua_assert(vreg == fs->f->numparams); lua_assert(vreg == fs->f->numparams);
t->u.ind.t = vreg; /* (avoid a direct assignment; values may overlap) */ t->u.ind.t = vreg; /* (avoid a direct assignment; values may overlap?) */
fillidxk(t, kreg, VVARGIND); /* 't' represents 'vararg[k]' */ fillidxk(t, kreg, VVARGIND); /* 't' represents 'vararg[k]' */
} }
else { else {
/* register index of the table */ /* register index of the table */
t->u.ind.t = cast_byte((t->k == VLOCAL) ? t->u.var.ridx: t->u.info); lu_byte temp = cast_byte((t->k == VLOCAL) ? t->u.var.ridx: t->u.info);
t->u.ind.t = temp; /* (avoid a direct assignment; values may overlap?) */
if (isKstr(fs, k)) if (isKstr(fs, k))
fillidxk(t, k->u.info, VINDEXSTR); /* literal short string */ fillidxk(t, k->u.info, VINDEXSTR); /* literal short string */
else if (isCint(k)) /* int. constant in proper range? */ else if (isCint(k)) /* int. constant in proper range? */