From 0c779c51c9ee0362106c04cdccb91a3bac478e70 Mon Sep 17 00:00:00 2001 From: Andrei Zmievski Date: Sat, 11 Dec 1999 20:00:40 +0000 Subject: [PATCH] (PHP php_implode) Made binary-safe. @ Made implode() binary-safe (Andrei) --- TODO | 1 - ext/standard/string.c | 26 +++++++++++++------------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/TODO b/TODO index 742530eea6f..e5d32e6e369 100644 --- a/TODO +++ b/TODO @@ -27,7 +27,6 @@ ext/standard * advanced sort (Andrei) * NOT binary safe: strcspn() - implode() strtok() basename() dirname() diff --git a/ext/standard/string.c b/ext/standard/string.c index f0b58ea4336..47896b913a5 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -265,19 +265,17 @@ PHP_FUNCTION(explode) PHPAPI void php_implode(pval *delim, pval *arr, pval *return_value) { pval **tmp; - int len = 0, count = 0; + int len = 0, count = 0, target = 0; /* convert everything to strings, and calculate length */ zend_hash_internal_pointer_reset(arr->value.ht); while (zend_hash_get_current_data(arr->value.ht, (void **) &tmp) == SUCCESS) { convert_to_string_ex(tmp); - if ((*tmp)->type == IS_STRING && (*tmp)->value.str.val != undefined_variable_string) { - len += (*tmp)->value.str.len; - if (count>0) { - len += delim->value.str.len; - } - count++; + len += (*tmp)->value.str.len; + if (count>0) { + len += delim->value.str.len; } + count++; zend_hash_move_forward(arr->value.ht); } @@ -287,12 +285,14 @@ PHPAPI void php_implode(pval *delim, pval *arr, pval *return_value) return_value->value.str.val[len] = '\0'; zend_hash_internal_pointer_reset(arr->value.ht); while (zend_hash_get_current_data(arr->value.ht, (void **) &tmp) == SUCCESS) { - if ((*tmp)->type == IS_STRING && (*tmp)->value.str.val != undefined_variable_string) { - count--; - strcat(return_value->value.str.val, (*tmp)->value.str.val); - if (count > 0) { - strcat(return_value->value.str.val, delim->value.str.val); - } + count--; + memcpy(return_value->value.str.val + target, (*tmp)->value.str.val, + (*tmp)->value.str.len); + target += (*tmp)->value.str.len; + if (count > 0) { + memcpy(return_value->value.str.val + target, delim->value.str.val, + delim->value.str.len); + target += delim->value.str.len; } zend_hash_move_forward(arr->value.ht); }