[Commits] SDL: SDL_vsnprintf() updates for zero-padding:

libsdl.org revision control commits-owner at libsdl.org
Wed Sep 26 23:37:45 PDT 2018


details:   https://hg.libsdl.org/SDL/rev/08b190d518fc
changeset: 12240:08b190d518fc
user:      Ozkan Sezer <sezeroz at gmail.com>
date:      Thu Sep 27 09:37:36 2018 +0300
description:
SDL_vsnprintf() updates for zero-padding:

- remove force-enabling of pad_zeroes for %u for compatibility
 (was added in https://hg.libsdl.org/SDL/rev/701f4a25df89)
- ignore pad_zeroes for %s and %S
- ignore pad_zeroes for %d, %i and %u if a precision is given

diffstat:

 src/stdlib/SDL_string.c |  11 +++++++++--
 1 files changed, 9 insertions(+), 2 deletions(-)

diffs (48 lines):

diff -r 55489adbb75c -r 08b190d518fc src/stdlib/SDL_string.c
--- a/src/stdlib/SDL_string.c	Wed Sep 26 20:10:32 2018 -0400
+++ b/src/stdlib/SDL_string.c	Thu Sep 27 09:37:36 2018 +0300
@@ -1415,7 +1415,7 @@
 
 static void
 SDL_IntPrecisionAdjust(char *num, size_t maxlen, SDL_FormatInfo *info)
-{/* left-pad num with zeroes, if needed. */
+{/* left-pad num with zeroes. */
     size_t sz, pad;
 
     if (!info || info->precision < 0)
@@ -1681,6 +1681,9 @@
                     break;
                 case 'i':
                 case 'd':
+                    if (info.precision >= 0) {
+                        info.pad_zeroes = SDL_FALSE;
+                    }
                     switch (inttype) {
                     case DO_INT:
                         len = SDL_PrintLong(text, left, &info,
@@ -1718,7 +1721,9 @@
                     }
                     /* Fall through to unsigned handling */
                 case 'u':
-                    info.pad_zeroes = SDL_TRUE;
+                    if (info.precision >= 0) {
+                        info.pad_zeroes = SDL_FALSE;
+                    }
                     switch (inttype) {
                     case DO_INT:
                         len = SDL_PrintUnsignedLong(text, left, &info,
@@ -1745,12 +1750,14 @@
                         /* In practice this is used on Windows for WCHAR strings */
                         wchar_t *wide_arg = va_arg(ap, wchar_t *);
                         char *arg = SDL_iconv_string("UTF-8", "UTF-16LE", (char *)(wide_arg), (SDL_wcslen(wide_arg)+1)*sizeof(*wide_arg));
+                        info.pad_zeroes = SDL_FALSE;
                         len = SDL_PrintString(text, left, &info, arg);
                         SDL_free(arg);
                         done = SDL_TRUE;
                     }
                     break;
                 case 's':
+                    info.pad_zeroes = SDL_FALSE;
                     len = SDL_PrintString(text, left, &info, va_arg(ap, char *));
                     done = SDL_TRUE;
                     break;


More information about the commits mailing list