mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-10-02 07:58:30 +00:00
Check return value of SDL_small_alloc()
Fixes https://github.com/libsdl-org/SDL/issues/8959
This commit is contained in:
@@ -3578,8 +3578,7 @@ bool SDL_RenderLines(SDL_Renderer *renderer, const SDL_FPoint *points, int count
|
||||
bool isstack1;
|
||||
bool isstack2;
|
||||
float *xy = SDL_small_alloc(float, 4 * 2 * count, &isstack1);
|
||||
int *indices = SDL_small_alloc(int,
|
||||
(4) * 3 * (count - 1) + (2) * 3 * (count), &isstack2);
|
||||
int *indices = SDL_small_alloc(int, (4) * 3 * (count - 1) + (2) * 3 * (count), &isstack2);
|
||||
|
||||
if (xy && indices) {
|
||||
int i;
|
||||
|
@@ -1497,20 +1497,7 @@ static SDL_Surface *GL_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect *
|
||||
|
||||
// Flip the rows to be top-down if necessary
|
||||
if (!renderer->target) {
|
||||
bool isstack;
|
||||
int length = rect->w * SDL_BYTESPERPIXEL(format);
|
||||
Uint8 *src = (Uint8 *)surface->pixels + (rect->h - 1) * surface->pitch;
|
||||
Uint8 *dst = (Uint8 *)surface->pixels;
|
||||
Uint8 *tmp = SDL_small_alloc(Uint8, length, &isstack);
|
||||
int rows = rect->h / 2;
|
||||
while (rows--) {
|
||||
SDL_memcpy(tmp, dst, length);
|
||||
SDL_memcpy(dst, src, length);
|
||||
SDL_memcpy(src, tmp, length);
|
||||
dst += surface->pitch;
|
||||
src -= surface->pitch;
|
||||
}
|
||||
SDL_small_free(tmp, isstack);
|
||||
SDL_FlipSurface(surface, SDL_FLIP_VERTICAL);
|
||||
}
|
||||
return surface;
|
||||
}
|
||||
|
@@ -348,15 +348,11 @@ static bool CompileShader(GL_ShaderContext *ctx, GLhandleARB shader, const char
|
||||
|
||||
ctx->glGetObjectParameterivARB(shader, GL_OBJECT_INFO_LOG_LENGTH_ARB, &length);
|
||||
info = SDL_small_alloc(char, length + 1, &isstack);
|
||||
ctx->glGetInfoLogARB(shader, length, NULL, info);
|
||||
SDL_LogError(SDL_LOG_CATEGORY_RENDER,
|
||||
"Failed to compile shader:\n%s%s\n%s", defines, source, info);
|
||||
#ifdef DEBUG_SHADERS
|
||||
fprintf(stderr,
|
||||
"Failed to compile shader:\n%s%s\n%s", defines, source, info);
|
||||
#endif
|
||||
SDL_small_free(info, isstack);
|
||||
|
||||
if (info) {
|
||||
ctx->glGetInfoLogARB(shader, length, NULL, info);
|
||||
SDL_LogError(SDL_LOG_CATEGORY_RENDER, "Failed to compile shader:\n%s%s\n%s", defines, source, info);
|
||||
SDL_small_free(info, isstack);
|
||||
}
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
|
@@ -2014,20 +2014,7 @@ static SDL_Surface *GLES2_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rec
|
||||
|
||||
// Flip the rows to be top-down if necessary
|
||||
if (!renderer->target) {
|
||||
bool isstack;
|
||||
int length = rect->w * SDL_BYTESPERPIXEL(format);
|
||||
Uint8 *src = (Uint8 *)surface->pixels + (rect->h - 1) * surface->pitch;
|
||||
Uint8 *dst = (Uint8 *)surface->pixels;
|
||||
Uint8 *tmp = SDL_small_alloc(Uint8, length, &isstack);
|
||||
int rows = rect->h / 2;
|
||||
while (rows--) {
|
||||
SDL_memcpy(tmp, dst, length);
|
||||
SDL_memcpy(dst, src, length);
|
||||
SDL_memcpy(src, tmp, length);
|
||||
dst += surface->pitch;
|
||||
src -= surface->pitch;
|
||||
}
|
||||
SDL_small_free(tmp, isstack);
|
||||
SDL_FlipSurface(surface, SDL_FLIP_VERTICAL);
|
||||
}
|
||||
return surface;
|
||||
}
|
||||
|
@@ -1103,22 +1103,8 @@ static SDL_Surface *VITA_GXM_RenderReadPixels(SDL_Renderer *renderer, const SDL_
|
||||
read_pixels(rect->x, y, rect->w, rect->h, surface->pixels);
|
||||
|
||||
// Flip the rows to be top-down if necessary
|
||||
|
||||
if (!renderer->target) {
|
||||
bool isstack;
|
||||
int length = rect->w * SDL_BYTESPERPIXEL(format);
|
||||
Uint8 *src = (Uint8 *)surface->pixels + (rect->h - 1) * surface->pitch;
|
||||
Uint8 *dst = (Uint8 *)surface->pixels;
|
||||
Uint8 *tmp = SDL_small_alloc(Uint8, length, &isstack);
|
||||
int rows = rect->h / 2;
|
||||
while (rows--) {
|
||||
SDL_memcpy(tmp, dst, length);
|
||||
SDL_memcpy(dst, src, length);
|
||||
SDL_memcpy(src, tmp, length);
|
||||
dst += surface->pitch;
|
||||
src -= surface->pitch;
|
||||
}
|
||||
SDL_small_free(tmp, isstack);
|
||||
SDL_FlipSurface(surface, SDL_FLIP_VERTICAL);
|
||||
}
|
||||
return surface;
|
||||
}
|
||||
|
Reference in New Issue
Block a user