summaryrefslogtreecommitdiff
path: root/lib/mprintf.c
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2014-05-04 23:37:24 +0200
committerDaniel Stenberg <daniel@haxx.se>2014-05-04 23:39:52 +0200
commit812da4190f8ac2f548f3bea09b85164b78d33347 (patch)
tree05918f43143c365d87ae0d85d41b89096278aba3 /lib/mprintf.c
parent312f36d453c763d96470d5d4cebd8aae28efe5dc (diff)
downloadcurl-812da4190f8ac2f548f3bea09b85164b78d33347.tar.gz
mprintf: allow %.s with data not being zero terminated
If the precision is indeed shorter than the string, don't strlen() to find the end because that's not how the precision operator works. I also added a unit test for curl_msnprintf to make sure this works and that the fix doesn't a few other basic use cases. I found a POSIX compliance problem that I marked TODO in the unit test, and I figure we need to add more tests in the future. Reported-by: Török Edwin
Diffstat (limited to 'lib/mprintf.c')
-rw-r--r--lib/mprintf.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/lib/mprintf.c b/lib/mprintf.c
index cc6042a3c..23070a764 100644
--- a/lib/mprintf.c
+++ b/lib/mprintf.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1999 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1999 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@@ -804,11 +804,11 @@ static int dprintf_formatf(
len = 0;
}
}
+ else if(prec != -1)
+ len = (size_t)prec;
else
len = strlen(str);
- if(prec != -1 && (size_t) prec < len)
- len = (size_t)prec;
width -= (long)len;
if(p->flags & FLAGS_ALT)
@@ -818,7 +818,7 @@ static int dprintf_formatf(
while(width-- > 0)
OUTCHAR(' ');
- while(len-- > 0)
+ while((len-- > 0) && *str)
OUTCHAR(*str++);
if(p->flags&FLAGS_LEFT)
while(width-- > 0)