Fixed return value of SDL_SaveBMP_RW() depending on set errors after NULL input.
authorPhilipp Wiesemann <philipp.wiesemann@arcor.de>
Thu, 16 Apr 2015 22:04:35 +0200
changeset 9563537881242756
parent 9562 96479df8e0bf
child 9566 7454bfce9202
child 11073 18f38a347662
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
     1.1 --- a/src/video/SDL_bmp.c	Thu Apr 16 22:02:03 2015 +0200
     1.2 +++ b/src/video/SDL_bmp.c	Thu Apr 16 22:04:35 2015 +0200
     1.3 @@ -531,6 +531,10 @@
     1.4                               format.BitsPerPixel);
     1.5              }
     1.6          }
     1.7 +    } else {
     1.8 +        /* Set no error here because it may overwrite a more useful message from
     1.9 +           SDL_RWFromFile() if SDL_SaveBMP_RW() is called from SDL_SaveBMP(). */
    1.10 +        return -1;
    1.11      }
    1.12  
    1.13      if (surface && (SDL_LockSurface(surface) == 0)) {