SDL_ttf: Fixed rendering wrapped text

From 9b2f3c7203cf01317c3512827aa6ef3b1939aa99 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Fri, 27 Sep 2024 00:18:44 -0700
Subject: [PATCH] Fixed rendering wrapped text

---
 src/SDL_ttf.c | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)

diff --git a/src/SDL_ttf.c b/src/SDL_ttf.c
index 7339dd2e..5c27a53e 100644
--- a/src/SDL_ttf.c
+++ b/src/SDL_ttf.c
@@ -3142,7 +3142,7 @@ static bool TTF_Size_Internal(TTF_Font *font, const char *text, size_t length, i
         font->pos_buf[font->pos_len].index = idx;
         font->pos_len += 1;
 
-        /* Compute previsionnal global bounding box */
+        /* Compute provisional global bounding box */
         pos_x = FT_FLOOR(pos_x) + glyph->sz_left;
         pos_y = FT_FLOOR(pos_y) - glyph->sz_top;
 
@@ -3405,6 +3405,9 @@ bool TTF_GetTextSizeWrapped(TTF_Font *font, const char *text, size_t length, int
     TTF_CHECK_INITIALIZED(false);
     TTF_CHECK_POINTER("font", font, false);
     TTF_CHECK_POINTER("text", text, false);
+    if (wrapLength < 0) {
+        return SDL_InvalidParamError("wrapLength");
+    }
 
     if (!length) {
         length = SDL_strlen(text);
@@ -3426,11 +3429,6 @@ bool TTF_GetTextSizeWrapped(TTF_Font *font, const char *text, size_t length, int
         goto done;
     }
 
-    if (wrapLength < 0) {
-        SDL_InvalidParamError("wrapLength");
-        goto done;
-    }
-
     numLines = 1;
 
     if (*text_cpy) {
@@ -3592,6 +3590,10 @@ static SDL_Surface* TTF_Render_Wrapped_Internal(TTF_Font *font, const char *text
     TTF_CHECK_INITIALIZED(NULL);
     TTF_CHECK_POINTER("font", font, NULL);
     TTF_CHECK_POINTER("text", text, NULL);
+    if (wrapLength < 0) {
+        SDL_InvalidParamError("wrapLength");
+        return NULL;
+    }
 
     if (!length) {
         length = SDL_strlen(text);
@@ -3618,11 +3620,6 @@ static SDL_Surface* TTF_Render_Wrapped_Internal(TTF_Font *font, const char *text
         goto failure;
     }
 
-    if (wrapLength < 0) {
-        SDL_InvalidParamError("wrapLength");
-        goto failure;
-    }
-
 #if TTF_USE_SDF
     /* Invalid cache if we were using SDF */
     if (render_mode != RENDER_BLENDED) {
@@ -3784,7 +3781,7 @@ static SDL_Surface* TTF_Render_Wrapped_Internal(TTF_Font *font, const char *text
         }
 
         /* Initialize xstart, ystart and compute positions */
-        if (!TTF_Size_Internal(font, text, length, &line_width, NULL, &xstart, &ystart, NO_MEASUREMENT)) {
+        if (!TTF_Size_Internal(font, text, 0, &line_width, NULL, &xstart, &ystart, NO_MEASUREMENT)) {
             goto failure;
         }