summaryrefslogtreecommitdiff
path: root/src/stdlib
diff options
context:
space:
mode:
authorOzkan Sezer <sezeroz@gmail.com>2018-09-26 10:40:02 +0300
committerOzkan Sezer <sezeroz@gmail.com>2018-09-26 10:40:02 +0300
commitb932e07c1784ef9814b59266c5b45ca927c023c5 (patch)
tree3392f9cfee0a27dde71e687886d7694b415a8b2d /src/stdlib
parentf4b1548c1e8c3e14c5005cec21ad5cd4ff68a7b4 (diff)
downloadsdl-b932e07c1784ef9814b59266c5b45ca927c023c5.tar.gz
SDL_vsnprintf: string printer now honors the precision. (bug #4263.)
Diffstat (limited to 'src/stdlib')
-rw-r--r--src/stdlib/SDL_string.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/stdlib/SDL_string.c b/src/stdlib/SDL_string.c
index db91a0431..0ba6be74d 100644
--- a/src/stdlib/SDL_string.c
+++ b/src/stdlib/SDL_string.c
@@ -1374,15 +1374,18 @@ static size_t
SDL_PrintString(char *text, size_t maxlen, SDL_FormatInfo *info, const char *string)
{
size_t length = 0;
- size_t slen;
+ size_t slen, sz;
if (string == NULL) {
string = "(null)";
}
- if (info && info->width && (size_t)info->width > SDL_strlen(string)) {
+ sz = SDL_strlen(string);
+ if (info && info->width > 0 && (size_t)info->width > sz) {
char fill = info->pad_zeroes ? '0' : ' ';
- size_t width = info->width - SDL_strlen(string);
+ size_t width = info->width - sz;
+ if (info->precision >= 0 && (size_t)info->precision < sz)
+ width += sz - (size_t)info->precision;
while (width-- > 0 && maxlen > 0) {
*text++ = fill;
++length;
@@ -1394,6 +1397,13 @@ SDL_PrintString(char *text, size_t maxlen, SDL_FormatInfo *info, const char *str
length += SDL_min(slen, maxlen);
if (info) {
+ if (info->precision >= 0 && info->precision < sz) {
+ slen = info->precision;
+ if (slen < maxlen) {
+ text[slen] = 0;
+ length -= (sz - slen);
+ }
+ }
if (info->force_case == SDL_CASE_LOWER) {
SDL_strlwr(text);
} else if (info->force_case == SDL_CASE_UPPER) {