]> granicus.if.org Git - php/commitdiff
MFH (Fix strdup() bug when USE_ZEND_ALLOC was disabled)
authorZeev Suraski <zeev@php.net>
Thu, 7 Apr 2005 14:00:00 +0000 (14:00 +0000)
committerZeev Suraski <zeev@php.net>
Thu, 7 Apr 2005 14:00:00 +0000 (14:00 +0000)
Zend/zend_alloc.c
Zend/zend_alloc.h

index e43ec4e532978d20b351c1586781c7c7923ff623..5e3c70d25cd2c21fa3c6d66122dc47593844818d 100644 (file)
@@ -388,6 +388,15 @@ ZEND_API char *_estrdup(const char *s ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC)
        return p;
 }
 
+#if !USE_ZEND_ALLOC
+char *_strndup(char *s, uint l)
+{
+       char *tmp = malloc(l+1);
+       tmp[l] = '\0';
+       memcpy(tmp, s, l);
+       return tmp;
+}
+#endif
 
 ZEND_API char *_estrndup(const char *s, uint length ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC)
 {
index 856919188f19854ba6e8eb34f08be37a4a10e8bc..62adc8e6622439c48515baca16415b47f52502fa 100644 (file)
@@ -133,6 +133,8 @@ ZEND_API char *_estrndup(const char *s, unsigned int length ZEND_FILE_LINE_DC ZE
 #include <string.h>
 #undef _GNU_SOURCE
 
+char *_strndup(char *s, uint l);
+                                                                                                                                
 /* Standard wrapper macros */
 #define emalloc(size)                                  malloc(size)
 #define safe_emalloc(nmemb, size, offset)              malloc((nmemb) * (size) + (offset))
@@ -141,7 +143,7 @@ ZEND_API char *_estrndup(const char *s, unsigned int length ZEND_FILE_LINE_DC ZE
 #define erealloc(ptr, size)                            realloc((ptr), (size))
 #define erealloc_recoverable(ptr, size)        realloc((ptr), (size))
 #define estrdup(s)                                             strdup(s)
-#define estrndup(s, length)                            strndup((s), (length))
+#define estrndup(s, length)                            _strndup((s), (length))
 
 /* Relay wrapper macros */
 #define emalloc_rel(size)                                      malloc(size)
@@ -151,7 +153,7 @@ ZEND_API char *_estrndup(const char *s, unsigned int length ZEND_FILE_LINE_DC ZE
 #define erealloc_rel(ptr, size)                                realloc((ptr), (size))
 #define erealloc_recoverable_rel(ptr, size)    realloc((ptr), (size))
 #define estrdup_rel(s)                                         strdup(s)
-#define estrndup_rel(s, length)                                strndup((s), (length))
+#define estrndup_rel(s, length)                                _strndup((s), (length))
 
 /* Selective persistent/non persistent allocation macros */
 #define pemalloc(size, persistent)             malloc(size)
@@ -169,7 +171,7 @@ ZEND_API char *_estrndup(const char *s, unsigned int length ZEND_FILE_LINE_DC ZE
 #define pestrdup_rel(s, persistent)                    strdup(s)
 
 #define safe_estrdup(ptr)  ((ptr)?(strdup(ptr)):(empty_string))
-#define safe_estrndup(ptr, len) ((ptr)?(strndup((ptr), (len))):(empty_string))
+#define safe_estrndup(ptr, len) ((ptr)?(_strndup((ptr), (len))):(empty_string))
 
 #endif