Don't overwrite the SDL_IOFromFile() error in SDL_LoadBMP()

Fixes https://github.com/libsdl-org/SDL/issues/11188
This commit is contained in:
Sam Lantinga
2024-10-13 09:36:25 -07:00
parent aed1f76248
commit b766c824bd

View File

@@ -589,7 +589,11 @@ done:
SDL_Surface *SDL_LoadBMP(const char *file)
{
return SDL_LoadBMP_IO(SDL_IOFromFile(file, "rb"), 1);
SDL_IOStream *stream = SDL_IOFromFile(file, "rb");
if (!stream) {
return NULL;
}
return SDL_LoadBMP_IO(stream, 1);
}
bool SDL_SaveBMP_IO(SDL_Surface *surface, SDL_IOStream *dst, bool closeio)
@@ -597,7 +601,7 @@ bool SDL_SaveBMP_IO(SDL_Surface *surface, SDL_IOStream *dst, bool closeio)
bool was_error = true;
Sint64 fp_offset, new_offset;
int i, pad;
SDL_Surface *intermediate_surface;
SDL_Surface *intermediate_surface = NULL;
Uint8 *bits;
bool save32bit = false;
bool saveLegacyBMP = false;
@@ -634,12 +638,14 @@ bool SDL_SaveBMP_IO(SDL_Surface *surface, SDL_IOStream *dst, bool closeio)
Uint32 bV4GammaBlue = 0;
// Make sure we have somewhere to save
intermediate_surface = NULL;
if (dst) {
if (!SDL_SurfaceValid(surface)) {
SDL_InvalidParamError("surface");
goto done;
}
if (!dst) {
SDL_InvalidParamError("dst");
goto done;
}
#ifdef SAVE_32BIT_BMP
// We can save alpha information in a 32-bit BMP
@@ -687,11 +693,6 @@ bool SDL_SaveBMP_IO(SDL_Surface *surface, SDL_IOStream *dst, bool closeio)
goto done;
}
}
} else {
/* Set no error here because it may overwrite a more useful message from
SDL_IOFromFile() if SDL_SaveBMP_IO() is called from SDL_SaveBMP(). */
goto done;
}
if (save32bit) {
saveLegacyBMP = SDL_GetHintBoolean(SDL_HINT_BMP_SAVE_LEGACY_FORMAT, false);
@@ -873,5 +874,9 @@ done:
bool SDL_SaveBMP(SDL_Surface *surface, const char *file)
{
return SDL_SaveBMP_IO(surface, SDL_IOFromFile(file, "wb"), true);
SDL_IOStream *stream = SDL_IOFromFile(file, "wb");
if (!stream) {
return false;
}
return SDL_SaveBMP_IO(surface, stream, true);
}