From 5a578a07832e44d6529865bbf086b83c02271933 Mon Sep 17 00:00:00 2001 From: Philipp Wiesemann Date: Thu, 16 Apr 2015 22:04:35 +0200 Subject: [PATCH] Fixed return value of SDL_SaveBMP_RW() depending on set errors after NULL input. If SDL_SaveBMP_RW() was called with NULL passed as SDL_RWops argument, different values were returned depending on SDL_GetError(). If no error was set before the call (or SDL_ClearError() was called) then 0 was returned. This is wrong because nothing was saved. If an error was set before the call then -1 was returned. This was fixed by directly returning -1 for NULL input instead of deciding based on SDL_GetError(). No new error is set because this would otherwise override a maybe more useful error set in SDL_RWFromFile() which is used by SDL_SaveBMP(). --- src/video/SDL_bmp.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/video/SDL_bmp.c b/src/video/SDL_bmp.c index f2b19fabd..3e6f5c938 100644 --- a/src/video/SDL_bmp.c +++ b/src/video/SDL_bmp.c @@ -531,6 +531,10 @@ SDL_SaveBMP_RW(SDL_Surface * saveme, SDL_RWops * dst, int freedst) format.BitsPerPixel); } } + } else { + /* Set no error here because it may overwrite a more useful message from + SDL_RWFromFile() if SDL_SaveBMP_RW() is called from SDL_SaveBMP(). */ + return -1; } if (surface && (SDL_LockSurface(surface) == 0)) {