]> git.lizzy.rs Git - dragonfireclient.git/commitdiff
Patch built-in Lua to fix miscompile on Android (#12347)
authorparadust7 <102263465+paradust7@users.noreply.github.com>
Sat, 21 May 2022 15:46:50 +0000 (08:46 -0700)
committerGitHub <noreply@github.com>
Sat, 21 May 2022 15:46:50 +0000 (17:46 +0200)
lib/lua/src/lgc.c

index e909c79a9696dd316aba56af686725b724189497..9141a1c60bc0235df545ac5aed3435b75ecc8013 100644 (file)
@@ -164,8 +164,13 @@ static int traversetable (global_State *g, Table *h) {
     markobject(g, h->metatable);
   mode = gfasttm(g, h->metatable, TM_MODE);
   if (mode && ttisstring(mode)) {  /* is there a weak mode? */
-    weakkey = (strchr(svalue(mode), 'k') != NULL);
-    weakvalue = (strchr(svalue(mode), 'v') != NULL);
+    // Android's 'FORTIFY libc' calls __builtin_object_size on the argument of strchr.
+    // 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? */
       h->marked &= ~(KEYWEAK | VALUEWEAK);  /* clear bits */
       h->marked |= cast_byte((weakkey << KEYWEAKBIT) |