diff options
author | Sverker Eriksson <[email protected]> | 2012-08-23 19:12:22 +0200 |
---|---|---|
committer | Sverker Eriksson <[email protected]> | 2012-08-23 19:12:22 +0200 |
commit | 0176b2a78f0257d88d9532803770eb0405beacb0 (patch) | |
tree | 855301ef197a0ccd546e9f5f27c570f7cd95d8a5 /erts | |
parent | 357bb3aabc58d4259fd4300e3345592ff39f3930 (diff) | |
parent | 152a67153ad0c9e5ca39651b725bdf11b4be35d6 (diff) | |
download | otp-0176b2a78f0257d88d9532803770eb0405beacb0.tar.gz otp-0176b2a78f0257d88d9532803770eb0405beacb0.tar.bz2 otp-0176b2a78f0257d88d9532803770eb0405beacb0.zip |
Merge branch 'maint'
Diffstat (limited to 'erts')
-rw-r--r-- | erts/lib_src/common/erl_printf_format.c | 13 |
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); |