From 7930c0282bbec7be92195218b3a1e9e58537e6f9 Mon Sep 17 00:00:00 2001
From: Sylvain <[EMAIL REDACTED]>
Date: Sat, 5 Apr 2025 21:03:17 +0200
Subject: [PATCH] Fixed bug #537 - prevent incrementing a null pointer
'image->buffer', which would be detected by UBsan sanitizer.
---
src/SDL_ttf.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/src/SDL_ttf.c b/src/SDL_ttf.c
index be517a18..7a9e4330 100644
--- a/src/SDL_ttf.c
+++ b/src/SDL_ttf.c
@@ -1188,11 +1188,16 @@ static bool Render_Line_##NAME(TTF_Font *font, SDL_Surface *textbuf, int xstart,
int remainder; \
Uint8 *saved_buffer = image->buffer; \
int saved_width = image->width; \
- image->buffer += alignment; \
+ \
/* Position updated after glyph rendering */ \
x = xstart + FT_FLOOR(x) + image->left; \
y = ystart + FT_FLOOR(y) - image->top; \
\
+ if (image->buffer == NULL) { \
+ continue; \
+ } \
+ image->buffer += alignment; \
+ \
/* Make sure glyph is inside textbuf */ \
above_w = x + image->width - textbuf->w; \
above_h = y + image->rows - textbuf->h; \