forked from Mirrorlandia_minetest/minetest
Patch built-in Lua to fix miscompile on Android (#12347)
This commit is contained in:
parent
9ee3dc71f1
commit
e1f707d7e1
@ -164,8 +164,13 @@ static int traversetable (global_State *g, Table *h) {
|
|||||||
markobject(g, h->metatable);
|
markobject(g, h->metatable);
|
||||||
mode = gfasttm(g, h->metatable, TM_MODE);
|
mode = gfasttm(g, h->metatable, TM_MODE);
|
||||||
if (mode && ttisstring(mode)) { /* is there a weak mode? */
|
if (mode && ttisstring(mode)) { /* is there a weak mode? */
|
||||||
weakkey = (strchr(svalue(mode), 'k') != NULL);
|
// Android's 'FORTIFY libc' calls __builtin_object_size on the argument of strchr.
|
||||||
weakvalue = (strchr(svalue(mode), 'v') != NULL);
|
// This produces an incorrect size for the expression `svalue(mode)`, causing
|
||||||
|
// an assertion. By placing it in a temporary, __builtin_object_size returns
|
||||||
|
// -1 (for unknown size) which functions correctly.
|
||||||
|
const char *tmp = svalue(mode);
|
||||||
|
weakkey = (strchr(tmp, 'k') != NULL);
|
||||||
|
weakvalue = (strchr(tmp, 'v') != NULL);
|
||||||
if (weakkey || weakvalue) { /* is really weak? */
|
if (weakkey || weakvalue) { /* is really weak? */
|
||||||
h->marked &= ~(KEYWEAK | VALUEWEAK); /* clear bits */
|
h->marked &= ~(KEYWEAK | VALUEWEAK); /* clear bits */
|
||||||
h->marked |= cast_byte((weakkey << KEYWEAKBIT) |
|
h->marked |= cast_byte((weakkey << KEYWEAKBIT) |
|
||||||
|
Loading…
Reference in New Issue
Block a user