From 7a9735b11efc9813edeffe3b620e355cca6ee171 Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Sat, 26 Sep 2026 23:03:21 +0300
Subject: [PATCH 80/80] fair_map_island_new(): Fix set-but-unused warning on
 ndebug builds

See RM #2298

Signed-off-by: Marko Lindqvist <cazfi74@gmail.com>
---
 server/generator/mapgen.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/server/generator/mapgen.c b/server/generator/mapgen.c
index c59517b3af..803d2cbe3d 100644
--- a/server/generator/mapgen.c
+++ b/server/generator/mapgen.c
@@ -3226,7 +3226,7 @@ static struct fair_tile *fair_map_island_new(int size, int startpos_num)
     struct fair_tile *pend;
     int n = ((river_pct * size * MAP_NUM_CARDINAL_DIRS
               * MAP_NUM_CARDINAL_DIRS) / 200);
-    int length_max = 3, length, l;
+    int length_max = 3, l;
     enum direction8 dir;
     int extra_idx;
     int dirs_num;
@@ -3283,7 +3283,11 @@ static struct fair_tile *fair_map_island_new(int size, int startpos_num)
 
       /* Check a river in one direction. */
       pend = nullptr;
-      length = -1;
+
+#if !defined(FREECIV_NDEBUG) || defined(FREECIV_DEBUG)
+      int length = -1;
+#endif
+
       dir = direction8_invalid();
       dirs_num = 0;
       for (j = 0; j < MAP_NUM_VALID_DIRS; j++) {
@@ -3335,7 +3339,10 @@ static struct fair_tile *fair_map_island_new(int size, int startpos_num)
         if (finished && fc_rand(++dirs_num) == 0) {
           dir = MAP_VALID_DIRS[j];
           pend = pftile2;
+
+#if !defined(FREECIV_NDEBUG) || defined(FREECIV_DEBUG)
           length = l;
+#endif
         }
       }
       if (pend == nullptr) {
@@ -3351,7 +3358,11 @@ static struct fair_tile *fair_map_island_new(int size, int startpos_num)
                 length);
       for (;;) {
         BV_SET(pftile->extras, extra_idx);
+
+#if !defined(FREECIV_NDEBUG) || defined(FREECIV_DEBUG)
         length--;
+#endif
+
         if (pftile == pend) {
           fc_assert(length == 0);
           break;
-- 
2.53.0

