Core: Sidestep GCC false-positive warnings

(cherry picked from commits acdb8667b56a43db6eee9a96ad61147bb80ea785
and 6733345f73d04aeca9fa94706ca7451a72433429)

Adds some more fixes for 4.5.

Co-authored-by: Lukas Tenbrink <lukas.tenbrink@gmail.com>
Co-authored-by: Rémi Verschelde <rverschelde@gmail.com>
This commit is contained in:
Arctis-Fireblight
2025-11-05 20:31:41 -06:00
parent fca98a6068
commit 40b8e483d6
2 changed files with 20 additions and 5 deletions

View File

@@ -2359,9 +2359,11 @@ void Image::initialize_data(const char **p_xpm) {
} break; } break;
case READING_PIXELS: { case READING_PIXELS: {
int y = line - colormap_size - 1; int y = line - colormap_size - 1;
#if defined(__GNUC__) && !defined(__clang__) #ifdef __MINGW32__
#pragma GCC diagnostic push // False positive only with MinGW-GCC. Don't silence for regular GCC/Clang
#pragma GCC diagnostic warning "-Wstringop-overflow=0" // as this is code that _could_ exhibit actual overflow bugs.
GODOT_GCC_WARNING_PUSH
GODOT_GCC_PRAGMA(GCC diagnostic warning "-Wstringop-overflow=0")
#endif #endif
for (int x = 0; x < size_width; x++) { for (int x = 0; x < size_width; x++) {
char pixelstr[6] = { 0, 0, 0, 0, 0, 0 }; 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); _put_pixelb(x, y, pixel_size, data_write, pixel);
} }
#if defined(__GNUC__) && !defined(__clang__) #ifdef __MINGW32__
#pragma GCC diagnostic pop GODOT_GCC_WARNING_POP
#endif #endif
if (y == (size_height - 1)) { if (y == (size_height - 1)) {

View File

@@ -5845,6 +5845,15 @@ String String::unquote() const {
return substr(1, length() - 2); 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<uint8_t> String::to_ascii_buffer() const { Vector<uint8_t> String::to_ascii_buffer() const {
const String *s = this; const String *s = this;
if (s->is_empty()) { if (s->is_empty()) {
@@ -5893,6 +5902,10 @@ Vector<uint8_t> String::to_utf16_buffer() const {
return retval; return retval;
} }
#ifdef __MINGW32__
GODOT_GCC_WARNING_POP
#endif
Vector<uint8_t> String::to_utf32_buffer() const { Vector<uint8_t> String::to_utf32_buffer() const {
const String *s = this; const String *s = this;
if (s->is_empty()) { if (s->is_empty()) {