From: Ilia Alshanetsky Date: Wed, 4 Feb 2009 15:03:12 +0000 (+0000) Subject: Syn spprintf fix with that of 5.3 and above X-Git-Tag: php-5.2.9RC1~5 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c4a9c79e287af898f59ed133a4a67e688c0f9569;p=php Syn spprintf fix with that of 5.3 and above --- diff --git a/configure.in b/configure.in index fd8ae48320..419b3f9736 100644 --- a/configure.in +++ b/configure.in @@ -579,6 +579,7 @@ strcoll \ strdup \ strerror \ strftime \ +strnlen \ strptime \ strstr \ strtok_r \ diff --git a/main/spprintf.c b/main/spprintf.c index aeecc6ca70..b21e1fe144 100644 --- a/main/spprintf.c +++ b/main/spprintf.c @@ -180,6 +180,13 @@ /* }}} */ +#if !HAVE_STRNLEN +static size_t strnlen(const char *s, size_t maxlen) { + char *r = memchr(s, '\0', maxlen); + return r ? r-s : maxlen; +} +#endif + /* * Do format conversion placing the output in buffer */ @@ -547,10 +554,10 @@ static void xbuf_format_converter(smart_str *xbuf, const char *fmt, va_list ap) case 'v': s = va_arg(ap, char *); if (s != NULL) { - if (adjust_precision && precision) { - s_len = precision; - } else { + if (!adjust_precision) { s_len = strlen(s); + } else { + s_len = strnlen(s, precision); } } else { s = S_NULL;