From cd25cb34359d4ed7ef57125ba1afa866eae9cf69 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Wed, 17 Jul 2024 14:07:33 -0700 Subject: [PATCH] Check SDL_LockSurface() return value --- src/render/software/SDL_render_sw.c | 8 ++++++-- src/render/software/SDL_rotate.c | 5 ++++- src/video/SDL_surface.c | 4 +++- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/render/software/SDL_render_sw.c b/src/render/software/SDL_render_sw.c index 4e462e75db..a9d2f1252b 100644 --- a/src/render/software/SDL_render_sw.c +++ b/src/render/software/SDL_render_sw.c @@ -135,7 +135,9 @@ static int SW_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture, size_t length; if (SDL_MUSTLOCK(surface)) { - SDL_LockSurface(surface); + if (SDL_LockSurface(surface) < 0) { + return -1; + } } src = (Uint8 *)pixels; dst = (Uint8 *)surface->pixels + @@ -341,7 +343,9 @@ static int SW_RenderCopyEx(SDL_Renderer *renderer, SDL_Surface *surface, SDL_Tex * necessary because this code is going to access the pixel buffer directly. */ if (SDL_MUSTLOCK(src)) { - SDL_LockSurface(src); + if (SDL_LockSurface(src) < 0) { + return -1; + } } /* Clone the source surface but use its pixel buffer directly. diff --git a/src/render/software/SDL_rotate.c b/src/render/software/SDL_rotate.c index 02382a8e6f..35446fd051 100644 --- a/src/render/software/SDL_rotate.c +++ b/src/render/software/SDL_rotate.c @@ -561,7 +561,10 @@ SDL_Surface *SDLgfx_rotateSurface(SDL_Surface *src, double angle, int smooth, in /* Lock source surface */ if (SDL_MUSTLOCK(src)) { - SDL_LockSurface(src); + if (SDL_LockSurface(src) < 0) { + SDL_DestroySurface(rz_dst); + return NULL; + } } /* check if the rotation is a multiple of 90 degrees so we can take a fast path and also somewhat reduce diff --git a/src/video/SDL_surface.c b/src/video/SDL_surface.c index 5714b11b2b..50734c06c8 100644 --- a/src/video/SDL_surface.c +++ b/src/video/SDL_surface.c @@ -2045,7 +2045,9 @@ int SDL_ReadSurfacePixel(SDL_Surface *surface, int x, int y, Uint8 *r, Uint8 *g, bytes_per_pixel = SDL_BYTESPERPIXEL(surface->format); if (SDL_MUSTLOCK(surface)) { - SDL_LockSurface(surface); + if (SDL_LockSurface(surface) < 0) { + return -1; + } } p = (Uint8 *)surface->pixels + y * surface->pitch + x * bytes_per_pixel;