aboutsummaryrefslogtreecommitdiff
path: root/src/lj_parse.c
diff options
context:
space:
mode:
authorMike Pall <mike>2025-03-11 23:04:30 +0100
committerMike Pall <mike>2025-03-11 23:04:30 +0100
commit538a82133ad6fddfd0ca64de167c4aca3bc1a2da (patch)
tree22fd80543291b6b51ba9a6f841719bab7ed7b3bd /src/lj_parse.c
parent84cb21ffaf648b472ff3884556e2c413e8abe179 (diff)
downloadluajit-v2.1.tar.gz
luajit-v2.1.tar.bz2
luajit-v2.1.zip
Change handling of nil value markers in template tables.HEADv2.1
Reported by Bernhard M. Wiedemann. #1348 #1155 Fixes from Peter Cawley, Christian Clason, Lewis Russell.
Diffstat (limited to 'src/lj_parse.c')
-rw-r--r--src/lj_parse.c20
1 files changed, 5 insertions, 15 deletions
diff --git a/src/lj_parse.c b/src/lj_parse.c
index 70097598..f4116380 100644
--- a/src/lj_parse.c
+++ b/src/lj_parse.c
@@ -1725,7 +1725,7 @@ static void expr_table(LexState *ls, ExpDesc *e)
1725 FuncState *fs = ls->fs; 1725 FuncState *fs = ls->fs;
1726 BCLine line = ls->linenumber; 1726 BCLine line = ls->linenumber;
1727 GCtab *t = NULL; 1727 GCtab *t = NULL;
1728 int vcall = 0, needarr = 0, fixt = 0; 1728 int vcall = 0, needarr = 0;
1729 uint32_t narr = 1; /* First array index. */ 1729 uint32_t narr = 1; /* First array index. */
1730 uint32_t nhash = 0; /* Number of hash entries. */ 1730 uint32_t nhash = 0; /* Number of hash entries. */
1731 BCReg freg = fs->freereg; 1731 BCReg freg = fs->freereg;
@@ -1769,9 +1769,10 @@ static void expr_table(LexState *ls, ExpDesc *e)
1769 lj_gc_anybarriert(fs->L, t); 1769 lj_gc_anybarriert(fs->L, t);
1770 if (expr_isk_nojump(&val)) { /* Add const key/value to template table. */ 1770 if (expr_isk_nojump(&val)) { /* Add const key/value to template table. */
1771 expr_kvalue(fs, v, &val); 1771 expr_kvalue(fs, v, &val);
1772 } else { /* Otherwise create dummy string key (avoids lj_tab_newkey). */ 1772 /* Mark nil value with table value itself to preserve the key. */
1773 settabV(fs->L, v, t); /* Preserve key with table itself as value. */ 1773 if (key.k == VKSTR && tvisnil(v)) settabV(fs->L, v, t);
1774 fixt = 1; /* Fix this later, after all resizes. */ 1774 } else { /* Preserve the key for the following non-const store. */
1775 settabV(fs->L, v, t);
1775 goto nonconst; 1776 goto nonconst;
1776 } 1777 }
1777 } else { 1778 } else {
@@ -1813,17 +1814,6 @@ static void expr_table(LexState *ls, ExpDesc *e)
1813 } else { 1814 } else {
1814 if (needarr && t->asize < narr) 1815 if (needarr && t->asize < narr)
1815 lj_tab_reasize(fs->L, t, narr-1); 1816 lj_tab_reasize(fs->L, t, narr-1);
1816 if (fixt) { /* Fix value for dummy keys in template table. */
1817 Node *node = noderef(t->node);
1818 uint32_t i, hmask = t->hmask;
1819 for (i = 0; i <= hmask; i++) {
1820 Node *n = &node[i];
1821 if (tvistab(&n->val)) {
1822 lj_assertFS(tabV(&n->val) == t, "bad dummy key in template table");
1823 setnilV(&n->val); /* Turn value into nil. */
1824 }
1825 }
1826 }
1827 lj_gc_check(fs->L); 1817 lj_gc_check(fs->L);
1828 } 1818 }
1829} 1819}