From 40b8e483d61cdc803e92da26026149605699b045 Mon Sep 17 00:00:00 2001 From: Arctis-Fireblight <6182060+Arctis-Fireblight@users.noreply.github.com> Date: Wed, 5 Nov 2025 20:31:41 -0600 Subject: [PATCH] Core: Sidestep GCC false-positive warnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (cherry picked from commits acdb8667b56a43db6eee9a96ad61147bb80ea785 and 6733345f73d04aeca9fa94706ca7451a72433429) Adds some more fixes for 4.5. Co-authored-by: Lukas Tenbrink Co-authored-by: Rémi Verschelde --- core/io/image.cpp | 12 +++++++----- core/string/ustring.cpp | 13 +++++++++++++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/core/io/image.cpp b/core/io/image.cpp index 7c9fffe108..4e8a8f66da 100644 --- a/core/io/image.cpp +++ b/core/io/image.cpp @@ -2359,9 +2359,11 @@ void Image::initialize_data(const char **p_xpm) { } break; case READING_PIXELS: { int y = line - colormap_size - 1; -#if defined(__GNUC__) && !defined(__clang__) -#pragma GCC diagnostic push -#pragma GCC diagnostic warning "-Wstringop-overflow=0" +#ifdef __MINGW32__ + // False positive only with MinGW-GCC. Don't silence for regular GCC/Clang + // as this is code that _could_ exhibit actual overflow bugs. + GODOT_GCC_WARNING_PUSH + GODOT_GCC_PRAGMA(GCC diagnostic warning "-Wstringop-overflow=0") #endif for (int x = 0; x < size_width; x++) { char pixelstr[6] = { 0, 0, 0, 0, 0, 0 }; @@ -2377,8 +2379,8 @@ void Image::initialize_data(const char **p_xpm) { } _put_pixelb(x, y, pixel_size, data_write, pixel); } -#if defined(__GNUC__) && !defined(__clang__) -#pragma GCC diagnostic pop +#ifdef __MINGW32__ + GODOT_GCC_WARNING_POP #endif if (y == (size_height - 1)) { diff --git a/core/string/ustring.cpp b/core/string/ustring.cpp index 8bf5850d4d..7c3e8197f6 100644 --- a/core/string/ustring.cpp +++ b/core/string/ustring.cpp @@ -5845,6 +5845,15 @@ String String::unquote() const { return substr(1, length() - 2); } +// MinGW-GCC false positives because CharStringT::length() is int (so possibly < 0). +// Don't silence for regular GCC/Clang as this is code that _could_ exhibit actual overflow bugs. +#ifdef __MINGW32__ +GODOT_GCC_WARNING_PUSH +GODOT_GCC_PRAGMA(GCC diagnostic warning "-Wstringop-overflow=0") +GODOT_GCC_WARNING_IGNORE("-Warray-bounds") +GODOT_GCC_WARNING_IGNORE("-Wrestrict") +#endif + Vector String::to_ascii_buffer() const { const String *s = this; if (s->is_empty()) { @@ -5893,6 +5902,10 @@ Vector String::to_utf16_buffer() const { return retval; } +#ifdef __MINGW32__ +GODOT_GCC_WARNING_POP +#endif + Vector String::to_utf32_buffer() const { const String *s = this; if (s->is_empty()) {