From 2004d891cb57c3445a4a1adfb29c092ffa734a00 Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Sat, 18 Mar 2023 04:55:47 +0200
Subject: [PATCH 11/11] lua-5.4.4: Apply upstream bug fix patch 10

See osdn #47593

Signed-off-by: Marko Lindqvist <cazfi74@gmail.com>
---
 dependencies/lua-5.4/Version.txt | 2 +-
 dependencies/lua-5.4/src/lvm.c   | 4 ++++
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/dependencies/lua-5.4/Version.txt b/dependencies/lua-5.4/Version.txt
index 6c896e68d3..4410372092 100644
--- a/dependencies/lua-5.4/Version.txt
+++ b/dependencies/lua-5.4/Version.txt
@@ -2,7 +2,7 @@ Sources here are from lua-5.4.4
 (http://www.lua.org/ftp/lua-5.4.4.tar.gz)
 
 Upstream bug fixes from https://www.lua.org/bugs.html applied:
-2, 3, 4, 5, 6, 7, 8, 9
+2, 3, 4, 5, 6, 7, 8, 9, 10
 
 Bug fix 1 is not relevant to freeciv.
 
diff --git a/dependencies/lua-5.4/src/lvm.c b/dependencies/lua-5.4/src/lvm.c
index 154a6262f2..be2a230f97 100644
--- a/dependencies/lua-5.4/src/lvm.c
+++ b/dependencies/lua-5.4/src/lvm.c
@@ -1386,6 +1386,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
         vmbreak;
       }
       vmcase(OP_MODK) {
+        savestate(L, ci);  /* in case of division by 0 */
         op_arithK(L, luaV_mod, luaV_modf);
         vmbreak;
       }
@@ -1398,6 +1399,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
         vmbreak;
       }
       vmcase(OP_IDIVK) {
+        savestate(L, ci);  /* in case of division by 0 */
         op_arithK(L, luaV_idiv, luai_numidiv);
         vmbreak;
       }
@@ -1444,6 +1446,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
         vmbreak;
       }
       vmcase(OP_MOD) {
+        savestate(L, ci);  /* in case of division by 0 */
         op_arith(L, luaV_mod, luaV_modf);
         vmbreak;
       }
@@ -1456,6 +1459,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
         vmbreak;
       }
       vmcase(OP_IDIV) {  /* floor division */
+        savestate(L, ci);  /* in case of division by 0 */
         op_arith(L, luaV_idiv, luai_numidiv);
         vmbreak;
       }
-- 
2.39.2