From 03f8528315fa46c95991a34f3325d7b33ae5538c Mon Sep 17 00:00:00 2001
From: Edward Rudd <urkle@outoforder.cc>
Date: Sat, 02 May 2020 21:48:36 +0000
Subject: [PATCH] Update source to SDL2 2.0.12

---
 source/src/stdlib/SDL_string.c |   86 ++++++++++++++++++++++++++++++------------
 1 files changed, 61 insertions(+), 25 deletions(-)

diff --git a/source/src/stdlib/SDL_string.c b/source/src/stdlib/SDL_string.c
index a563adf..857c40b 100644
--- a/source/src/stdlib/SDL_string.c
+++ b/source/src/stdlib/SDL_string.c
@@ -1,6 +1,6 @@
 /*
   Simple DirectMedia Layer
-  Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+  Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
 
   This software is provided 'as-is', without any express or implied
   warranty.  In no event will the authors be held liable for any damages
@@ -421,17 +421,6 @@
 #endif /* HAVE_STRLEN */
 }
 
-wchar_t *
-SDL_wcsdup(const wchar_t *string)
-{
-    size_t len = ((SDL_wcslen(string) + 1) * sizeof(wchar_t));
-    wchar_t *newstr = (wchar_t *)SDL_malloc(len);
-    if (newstr) {
-        SDL_memcpy(newstr, string, len);
-    }
-    return newstr;
-}
-
 size_t
 SDL_wcslen(const wchar_t * string)
 {
@@ -477,6 +466,34 @@
 #endif /* HAVE_WCSLCAT */
 }
 
+wchar_t *
+SDL_wcsdup(const wchar_t *string)
+{
+    size_t len = ((SDL_wcslen(string) + 1) * sizeof(wchar_t));
+    wchar_t *newstr = (wchar_t *)SDL_malloc(len);
+    if (newstr) {
+        SDL_memcpy(newstr, string, len);
+    }
+    return newstr;
+}
+
+wchar_t *
+SDL_wcsstr(const wchar_t *haystack, const wchar_t *needle)
+{
+#if defined(HAVE_WCSSTR)
+    return SDL_const_cast(wchar_t*,wcsstr(haystack, needle));
+#else
+    size_t length = SDL_wcslen(needle);
+    while (*haystack) {
+        if (SDL_wcsncmp(haystack, needle, length) == 0) {
+            return (wchar_t *)haystack;
+        }
+        ++haystack;
+    }
+    return NULL;
+#endif /* HAVE_WCSSTR */
+}
+
 int
 SDL_wcscmp(const wchar_t *str1, const wchar_t *str2)
 {
@@ -491,6 +508,22 @@
     }
     return (int)(*str1 - *str2);
 #endif /* HAVE_WCSCMP */
+}
+
+int
+SDL_wcsncmp(const wchar_t *str1, const wchar_t *str2, size_t maxlen)
+{
+#if defined(HAVE_WCSNCMP)
+    return wcsncmp(str1, str2, maxlen);
+#else
+    while (*str1 && *str2) {
+        if (*str1 != *str2)
+            break;
+        ++str1;
+        ++str2;
+    }
+    return (int)(*str1 - *str2);
+#endif /* HAVE_WCSNCMP */
 }
 
 size_t
@@ -549,7 +582,7 @@
     const char *p = str;
     char ch;
 
-    while ((ch = *(p++))) {
+    while ((ch = *(p++)) != 0) {
         /* if top two bits are 1 and 0, it's a continuation byte. */
         if ((ch & 0xc0) != 0x80) {
             retval++;
@@ -818,7 +851,7 @@
 double SDL_atof(const char *string)
 {
 #ifdef HAVE_ATOF
-    return (double) atof(string);
+    return atof(string);
 #else
     return SDL_strtod(string, NULL);
 #endif /* HAVE_ATOF */
@@ -1387,15 +1420,18 @@
 
     sz = SDL_strlen(string);
     if (info && info->width > 0 && (size_t)info->width > sz) {
-        char fill = info->pad_zeroes ? '0' : ' ';
+        const char fill = info->pad_zeroes ? '0' : ' ';
         size_t width = info->width - sz;
+        size_t filllen;
+
         if (info->precision >= 0 && (size_t)info->precision < sz)
             width += sz - (size_t)info->precision;
-        while (width-- > 0 && maxlen > 0) {
-            *text++ = fill;
-            ++length;
-            --maxlen;
-        }
+
+        filllen = SDL_min(width, maxlen);
+        SDL_memset(text, fill, filllen);
+        text += filllen;
+        length += filllen;
+        maxlen -= filllen;
     }
 
     slen = SDL_strlcpy(text, string, maxlen);
@@ -1580,7 +1616,7 @@
 
     width = info->width - (int)(text - textstart);
     if (width > 0) {
-        char fill = info->pad_zeroes ? '0' : ' ';
+        const char fill = info->pad_zeroes ? '0' : ' ';
         char *end = text+left-1;
         len = (text - textstart);
         for (len = (text - textstart); len--; ) {
@@ -1596,10 +1632,10 @@
             text += len;
             left -= len;
         }
-        while (len--) {
-            if (textstart+len < end) {
-                textstart[len] = fill;
-            }
+
+        if (end != textstart) {
+            const size_t filllen = SDL_min(len, ((size_t) (end - textstart)) - 1);
+            SDL_memset(textstart, fill, filllen);
         }
     }
 

--
Gitblit v1.9.3