cvs: ZendEngine2 / zend_alloc.c zend_alloc.h
| From: | Zeev Suraski | Date: | Thu, 07 Apr 2005 13:59:46 +0000 |
| Subject: | cvs: ZendEngine2 / zend_alloc.c zend_alloc.h | ||
| Groups: | php.zend-engine.cvs | ||
| Request: | Send a blank email to php-zend-engine-cvs+get-3537@lists.php.net to get a copy of this message | ||
zeev Thu Apr 7 09:59:46 2005 EDT
Modified files:
/ZendEngine2 zend_alloc.c zend_alloc.h
Log:
Fix strdup() bug when USE_ZEND_ALLOC is disabled
http://cvs.php.net/diff.php/ZendEngine2/zend_alloc.c?r1=1.141&r2=1.142&ty=u
Index: ZendEngine2/zend_alloc.c
diff -u ZendEngine2/zend_alloc.c:1.141 ZendEngine2/zend_alloc.c:1.142
--- ZendEngine2/zend_alloc.c:1.141 Fri Aug 27 12:49:14 2004
+++ ZendEngine2/zend_alloc.c Thu Apr 7 09:59:45 2005
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: zend_alloc.c,v 1.141 2004/08/27 16:49:14 andi Exp $ */
+/* $Id: zend_alloc.c,v 1.142 2005/04/07 13:59:45 zeev Exp $ */
#include "zend.h"
#include "zend_alloc.h"
@@ -409,6 +409,15 @@
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)
{
http://cvs.php.net/diff.php/ZendEngine2/zend_alloc.h?r1=1.58&r2=1.59&ty=u
Index: ZendEngine2/zend_alloc.h
diff -u ZendEngine2/zend_alloc.h:1.58 ZendEngine2/zend_alloc.h:1.59
--- ZendEngine2/zend_alloc.h:1.58 Wed Aug 11 02:11:07 2004
+++ ZendEngine2/zend_alloc.h Thu Apr 7 09:59:45 2005
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: zend_alloc.h,v 1.58 2004/08/11 06:11:07 derick Exp $ */
+/* $Id: zend_alloc.h,v 1.59 2005/04/07 13:59:45 zeev Exp $ */
#ifndef ZEND_ALLOC_H
#define ZEND_ALLOC_H
@@ -134,6 +134,8 @@
#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))
@@ -142,7 +144,7 @@
#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)
@@ -152,7 +154,7 @@
#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)
@@ -171,7 +173,7 @@
#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