aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSverker Eriksson <[email protected]>2012-08-23 19:09:10 +0200
committerSverker Eriksson <[email protected]>2012-08-23 19:09:10 +0200
commit152a67153ad0c9e5ca39651b725bdf11b4be35d6 (patch)
tree59231fb696eb43a80e426320c74150082b6d5acc
parent9a9dee8bf12212830be738932c4cdb45f2db2260 (diff)
parent7fc31186ee1afbc1fb5b47b02e412a7546711cb0 (diff)
downloadotp-152a67153ad0c9e5ca39651b725bdf11b4be35d6.tar.gz
otp-152a67153ad0c9e5ca39651b725bdf11b4be35d6.tar.bz2
otp-152a67153ad0c9e5ca39651b725bdf11b4be35d6.zip
Merge branch 'sverk/printf-string-precision-bug' into maint
* sverk/printf-string-precision-bug: erts: Fix bug in erts_printf for %s with precision
-rw-r--r--erts/lib_src/common/erl_printf_format.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/erts/lib_src/common/erl_printf_format.c b/erts/lib_src/common/erl_printf_format.c
index 473791dce4..71d2aa35d0 100644
--- a/erts/lib_src/common/erl_printf_format.c
+++ b/erts/lib_src/common/erl_printf_format.c
@@ -457,6 +457,15 @@ static int fmt_double(fmtfn_t fn,void*arg,double val,
return res;
}
+/* strnlen doesn't exist everywhere */
+static size_t my_strnlen(const char *s, size_t maxlen)
+{
+ size_t i = 0;
+ while (i < maxlen && s[i] != '\0')
+ i++;
+ return i;
+}
+
int erts_printf_format(fmtfn_t fn, void* arg, char* fmt, va_list ap)
{
char* ptr0 = fmt;
@@ -771,9 +780,7 @@ int erts_printf_format(fmtfn_t fn, void* arg, char* fmt, va_list ap)
case FMTC_s: {
char* str = va_arg(ap,char*);
- int len = strlen(str);
- if (precision >= 0 && precision < len)
- len = precision;
+ int len = (precision >= 0) ? my_strnlen(str,precision) : strlen(str);
if (width > 0 && !(fmt & FMTF_adj)) {
if (width > len)
BLANKS(fn, arg, width - len, count);