From 4251f2ab8a83ae7bf48d8670a4ce23a0f69f6dc1 Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Wed, 16 Feb 2022 00:09:46 +0200
Subject: [PATCH 46/46] Qt: Iterate gfx extensions without removing them from
 the list

Refactor gfx_fileextensions() that was apparently causing
Qt6-client on Windows to later crash on random location.

See osdn #43755

Signed-off-by: Marko Lindqvist <cazfi74@gmail.com>
---
 client/gui-qt/sprite.cpp | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/client/gui-qt/sprite.cpp b/client/gui-qt/sprite.cpp
index d868936be6..07c18f2162 100644
--- a/client/gui-qt/sprite.cpp
+++ b/client/gui-qt/sprite.cpp
@@ -35,7 +35,7 @@ static const char **gfx_array_extensions = nullptr;
 const char **gfx_fileextensions(void)
 {
   QList<QByteArray> gfx_ext;
-  QByteArray cp;
+  QList<QByteArray>::iterator iter;
   int j = 0;
 
   if (gfx_array_extensions != nullptr) {
@@ -45,12 +45,11 @@ const char **gfx_fileextensions(void)
   gfx_ext = QImageReader::supportedImageFormats();
 
   gfx_array_extensions = new const char *[gfx_ext.count() + 1];
-  while (!gfx_ext.isEmpty()) {
+  for (iter = gfx_ext.begin(); iter != gfx_ext.end(); iter++) {
     char *ext;
 
-    cp = gfx_ext.takeFirst();
-    ext = static_cast<char *>(fc_malloc(sizeof(cp.data())));
-    strncpy(ext, cp.data(), sizeof(cp));
+    ext = static_cast<char *>(fc_malloc(sizeof(iter->data())));
+    strncpy(ext, iter->data(), sizeof(iter->data()));
     gfx_array_extensions[j] = ext;
     j++;
   }
-- 
2.34.1