From 9b0e478f193143d3ce043ff43b68c0dc4ad7f7b1 Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Wed, 16 Feb 2022 00:09:46 +0200
Subject: [PATCH 31/36] 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 | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/client/gui-qt/sprite.cpp b/client/gui-qt/sprite.cpp
index d868936be6..f010e9a72e 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,12 @@ 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;
+    int extlen = iter->size() + 1;
 
-    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(extlen));
+    strncpy(ext, iter->data(), extlen);
     gfx_array_extensions[j] = ext;
     j++;
   }
-- 
2.34.1