Skip to content

Commit

Permalink
Do error checking when allocating a palette
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Jul 12, 2024
1 parent aba2fd9 commit 99468fc
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/SDL_ttf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1444,14 +1444,21 @@ static SDL_Surface *AllocateAlignedPixels(size_t width, size_t height, SDL_Pixel
SDL_aligned_free(pixels);
return NULL;
}
if (SDL_ISPIXELFORMAT_INDEXED(format)) {
SDL_SetSurfacePalette(textbuf, SDL_CreatePalette(1 << SDL_BITSPERPIXEL(format)));
}

/* Let SDL handle the memory allocation */
textbuf->flags &= ~SDL_SURFACE_PREALLOCATED;
textbuf->flags |= SDL_SURFACE_SIMD_ALIGNED;

/* Allocate a palette if needed */
if (SDL_ISPIXELFORMAT_INDEXED(format)) {
SDL_Palette *palette = SDL_CreatePalette(1 << SDL_BITSPERPIXEL(format));
if (!palette) {
SDL_DestroySurface(textbuf);
return NULL;
}
SDL_SetSurfacePalette(textbuf, palette);
}

if (bytes_per_pixel == 4) {
SDL_memset4(pixels, bgcolor, size / 4);
}
Expand Down

0 comments on commit 99468fc

Please sign in to comment.