From aaab1b9e98e8bbca572064ceb23f0fd916b2add5 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Wed, 26 Feb 2025 16:40:59 -0800
Subject: [PATCH] Don't crash if we break a line between '\r' and '\n'
We probably shouldn't be doing that anyway, but at least we won't crash now if we do.
Fixes https://github.com/libsdl-org/SDL_ttf/issues/517
---
src/SDL_ttf.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/SDL_ttf.c b/src/SDL_ttf.c
index b39810d6..8239223c 100644
--- a/src/SDL_ttf.c
+++ b/src/SDL_ttf.c
@@ -4196,7 +4196,7 @@ static bool GetWrappedLines(TTF_Font *font, const char *text, size_t length, TTF
// The line doesn't include any delimiter that caused it to be wrapped.
if (CharacterIsNewLine(line->text[line->length - 1])) {
--line->length;
- if (line->text[line->length - 1] == '\r') {
+ if (line->length > 0 && line->text[line->length - 1] == '\r') {
--line->length;
}
} else if (i < (numLines - 1) &&