moriyoshi Thu Mar 27 16:13:47 2003 EDT
Modified files:
/php4/main php_variables.c
Log:
Improved php_import_environment_variables: avoid emalloc()ing in most cases
Index: php4/main/php_variables.c
diff -u php4/main/php_variables.c:1.57 php4/main/php_variables.c:1.58
--- php4/main/php_variables.c:1.57 Tue Mar 25 03:07:12 2003
+++ php4/main/php_variables.c Thu Mar 27 16:13:47 2003
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_variables.c,v 1.57 2003/03/25 08:07:12 sebastian Exp $ */
+/* $Id: php_variables.c,v 1.58 2003/03/27 21:13:47 moriyoshi Exp $ */
#include <stdio.h>
#include "php.h"
@@ -344,7 +344,11 @@
void _php_import_environment_variables(zval *array_ptr TSRMLS_DC)
{
- char **env, *p, *t;
+ char buf[128];
+ char **env, *p, *t = buf;
+ size_t alloc_size = sizeof(buf);
+ unsigned int nlen; /* ptrdiff_t is not portable */
+
/* turn off magic_quotes while importing environment variables */
int magic_quotes_gpc = PG(magic_quotes_gpc);
PG(magic_quotes_gpc) = 0;
@@ -354,8 +358,16 @@
if (!p) { /* malformed entry? */
continue;
}
- t = estrndup(*env, p - *env);
+ nlen = p - *env;
+ if (nlen >= alloc_size) {
+ alloc_size = nlen + 64;
+ t = (t == buf ? emalloc(alloc_size): erealloc(t, alloc_size));
+ }
+ memcpy(t, *env, nlen);
+ t[nlen] = '\0';
php_register_variable(t, p+1, array_ptr TSRMLS_CC);
+ }
+ if (t != buf && t != NULL) {
efree(t);
}
PG(magic_quotes_gpc) = magic_quotes_gpc;
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php