For any TTF_Text that includes line breaks and uses a non-zero wrapping width, its total width as reported by TTF_GetTextSize will always be equal to the wrapping width, regardless of actual text size. Example:
TTF_Text* text = TTF_CreateText(text_engine, font, "a\nb\nc", 0);
TTF_SetTextWrapWidth(text, 999999);
int width = 0;
int height = 0;
TTF_GetTextSize(text, &width, &height);
assert(width == 999999);
It seems this branch based on wrap_width is the culprit, as it ends up assuming all multiline wrapping texts must've reached the wrapping width, which isn't always true.