SDL-1.2: SDL_iconv_string: avoid infinite loop when encountering invalid chars.

From b6ce1213992072b9cb209c4dca1f16c1aca8423a Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Tue, 10 Mar 2020 16:29:28 -0700
Subject: [PATCH] SDL_iconv_string: avoid infinite loop when encountering
 invalid chars.

Backport from SDL2 commit 342f62ca690972a0cc376d537 for SDL2 bug/5022.
---
 src/stdlib/SDL_iconv.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/src/stdlib/SDL_iconv.c b/src/stdlib/SDL_iconv.c
index 9177879e..950911f3 100644
--- a/src/stdlib/SDL_iconv.c
+++ b/src/stdlib/SDL_iconv.c
@@ -847,6 +847,7 @@ char *SDL_iconv_string(const char *tocode, const char *fromcode, const char *inb
 	SDL_memset(outbuf, 0, 4);
 
 	while ( inbytesleft > 0 ) {
+		const size_t oldinbytesleft = inbytesleft;
 		retCode = SDL_iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
 		switch (retCode) {
 		    case SDL_ICONV_E2BIG:
@@ -875,6 +876,10 @@ char *SDL_iconv_string(const char *tocode, const char *fromcode, const char *inb
 			inbytesleft = 0;
 			break;
 		}
+		/* Avoid infinite loops when nothing gets converted */
+		if (oldinbytesleft == inbytesleft) {
+			break;
+		}
 	}
 	SDL_iconv_close(cd);