]> granicus.if.org Git - php/commitdiff
MFB
authorNuno Lopes <nlopess@php.net>
Fri, 12 Dec 2008 23:55:48 +0000 (23:55 +0000)
committerNuno Lopes <nlopess@php.net>
Fri, 12 Dec 2008 23:55:48 +0000 (23:55 +0000)
configure.in
main/spprintf.c

index a811f757665f1365897366c1f6a94841ee8d8d42..861ef41cde2ad445477d02af0b29bff616fd046f 100644 (file)
@@ -625,6 +625,7 @@ strcoll \
 strdup \
 strerror \
 strftime \
+strnlen \
 strptime \
 strstr \
 strtok_r \
index 90f3c380fb930730691dcad1dbc22fb3ef1f6c05..be0db3487a3893b39da0faa295e05daba97c8f98 100644 (file)
@@ -77,6 +77,7 @@
  * <panos@alumni.cs.colorado.edu> for xinetd.
  */
 
+#define _GNU_SOURCE
 #include "php.h"
 
 #include <stddef.h>
@@ -209,6 +210,14 @@ do {                                                                                               \
 
 /* }}} */
 
+
+#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
  */
@@ -656,9 +665,11 @@ fmt_unicode:
 fmt_string:
                                        s = va_arg(ap, char *);
                                        if (s != NULL) {
-                                               s_len = strlen(s);
-                                               if (adjust_precision && precision < s_len)
-                                                       s_len = precision;
+                                               if (!adjust_precision) {
+                                                       s_len = strlen(s);
+                                               } else {
+                                                       s_len = strnlen(s, precision);
+                                               }
                                        } else {
                                                s = S_NULL;
                                                s_len = S_NULL_LEN;