From e81e124c62b5ec9a6cc33843af5e6ef08863d27d Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Sun, 25 Oct 2026 11:48:57 +0200
Subject: [PATCH 93/93] Apply patch 3 for lua-5.5.1

See RM #2409

Signed-off-by: Marko Lindqvist <cazfi74@gmail.com>
---
 dependencies/lua-5.5/Version.txt | 2 +-
 dependencies/lua-5.5/src/lcode.c | 6 +++++-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/dependencies/lua-5.5/Version.txt b/dependencies/lua-5.5/Version.txt
index 760821b08c..bcf9d9a4c0 100644
--- a/dependencies/lua-5.5/Version.txt
+++ b/dependencies/lua-5.5/Version.txt
@@ -2,7 +2,7 @@ Sources here are from lua-5.5.1
 (http://www.lua.org/ftp/lua-5.5.1.tar.gz)
 
 Upstream bug fixes from https://www.lua.org/bugs.html applied:
-1, 2
+1, 2, 3
 
 Not entire lua distribution directory hierarchy is included here, and
 some files needed for Freeciv usage have been added.
diff --git a/dependencies/lua-5.5/src/lcode.c b/dependencies/lua-5.5/src/lcode.c
index 10d8f9081d..1011a63217 100644
--- a/dependencies/lua-5.5/src/lcode.c
+++ b/dependencies/lua-5.5/src/lcode.c
@@ -1543,15 +1543,19 @@ static void codebinK (FuncState *fs, BinOpr opr,
 
 /* Try to code a binary operator negating its second operand.
 ** For the metamethod, 2nd operand must keep its original value.
+** As a special case, avoid the optimization for (exp - 0), because
+** (-0.0 - 0) is -0.0, while (-0.0 + 0) is +0.0.
 */
 static int finishbinexpneg (FuncState *fs, expdesc *e1, expdesc *e2,
-                             OpCode op, int line, TMS event) {
+                            OpCode op, int line, TMS event) {
   if (!isKint(e2))
     return 0;  /* not an integer constant */
   else {
     lua_Integer i2 = e2->u.ival;
     if (!(fitsC(i2) && fitsC(-i2)))
       return 0;  /* not in the proper range */
+    if (event == TM_SUB && i2 == 0)
+      return 0;  /* do not optimize (exp - 0) */
     else {  /* operating a small integer constant */
       int v2 = cast_int(i2);
       finishbinexpval(fs, e1, e2, op, int2sC(-v2), 0, line, OP_MMBINI, event);
-- 
2.53.0

