summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/ldap/ldap.c33
-rw-r--r--ext/mbstring/mbstring.c255
-rw-r--r--ext/mbstring/php_mbregex.c61
3 files changed, 143 insertions, 206 deletions
diff --git a/ext/ldap/ldap.c b/ext/ldap/ldap.c
index 7fd92bbf4f..d79a2af171 100644
--- a/ext/ldap/ldap.c
+++ b/ext/ldap/ldap.c
@@ -685,11 +685,7 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
efree(ldap_attrs);
}
- if (array_init(return_value) == FAILURE) {
- efree(lds);
- efree(rcs);
- RETURN_FALSE;
- }
+ array_init(return_value);
/* Collect results from the searches */
for (i=0; i<nlinks; i++) {
@@ -1107,9 +1103,7 @@ PHP_FUNCTION(ldap_get_values)
num_values = ldap_count_values(ldap_value);
- if (array_init(return_value) == FAILURE) {
- RETURN_FALSE;
- }
+ array_init(return_value);
for(i=0; i<num_values; i++) {
add_next_index_string(return_value, ldap_value[i], 1);
@@ -1148,10 +1142,7 @@ PHP_FUNCTION(ldap_get_values_len)
}
num_values = ldap_count_values_len(ldap_value_len);
- if (array_init(return_value) == FAILURE) {
- php_error(E_ERROR, "%s(): Cannot initialize return value", get_active_function_name(TSRMLS_C));
- RETURN_FALSE;
- }
+ array_init(return_value);
for (i=0; i<num_values; i++) {
add_next_index_stringl(return_value, ldap_value_len[i]->bv_val, ldap_value_len[i]->bv_len, 1);
@@ -1214,9 +1205,7 @@ PHP_FUNCTION(ldap_explode_dn)
while(ldap_value[i] != NULL) i++;
count = i;
- if (array_init(return_value) == FAILURE) {
- RETURN_FALSE;
- }
+ array_init(return_value);
add_assoc_long(return_value, "count", count);
for(i=0; i<count; i++) {
@@ -1807,13 +1796,7 @@ PHP_FUNCTION(ldap_parse_result)
switch(myargcount) {
case 6 :
zval_dtor(*referrals);
- if (array_init(*referrals) == FAILURE) {
- php_error(E_ERROR, "%s(): Cannot initialize return value", get_active_function_name(TSRMLS_C));
- ldap_value_free(lreferrals);
- ldap_memfree(lerrmsg);
- ldap_memfree(lmatcheddn);
- RETURN_FALSE;
- }
+ array_init(*referrals);
if (lreferrals != NULL) {
refp = lreferrals;
while (*refp) {
@@ -1921,11 +1904,7 @@ PHP_FUNCTION(ldap_parse_reference)
}
zval_dtor(*referrals);
- if (array_init(*referrals) == FAILURE) {
- php_error(E_ERROR, "%s(): Cannot initialize return value", get_active_function_name(TSRMLS_C));
- ldap_value_free(lreferrals);
- RETURN_FALSE;
- }
+ array_init(*referrals);
if (lreferrals != NULL) {
refp = lreferrals;
while (*refp) {
diff --git a/ext/mbstring/mbstring.c b/ext/mbstring/mbstring.c
index 71b7a05e95..c76c24b85e 100644
--- a/ext/mbstring/mbstring.c
+++ b/ext/mbstring/mbstring.c
@@ -820,13 +820,11 @@ PHP_RINIT_FUNCTION(mbstring)
n = php_mb_default_identify_list_size;
}
entry = (int *)emalloc(n*sizeof(int));
- if (entry != NULL) {
- MBSTRG(current_detect_order_list) = entry;
- MBSTRG(current_detect_order_list_size) = n;
- while (n > 0) {
- *entry++ = *list++;
- n--;
- }
+ MBSTRG(current_detect_order_list) = entry;
+ MBSTRG(current_detect_order_list_size) = n;
+ while (n > 0) {
+ *entry++ = *list++;
+ n--;
}
/* override original function. */
@@ -1031,9 +1029,7 @@ PHP_FUNCTION(mb_http_input)
break;
case 'I':
case 'i':
- if (array_init(return_value) == FAILURE) {
- RETURN_FALSE;
- }
+ array_init(return_value);
entry = MBSTRG(http_input_list);
n = MBSTRG(http_input_list_size);
while (n > 0) {
@@ -1133,9 +1129,7 @@ PHP_FUNCTION(mb_detect_order)
char *name;
if (ZEND_NUM_ARGS() == 0) {
- if (array_init(return_value) == FAILURE) {
- RETURN_FALSE;
- }
+ array_init(return_value);
entry = MBSTRG(current_detect_order_list);
n = MBSTRG(current_detect_order_list_size);
while (n > 0) {
@@ -2463,9 +2457,6 @@ PHP_FUNCTION(mb_convert_variables)
WRONG_PARAM_COUNT;
}
args = (pval ***)ecalloc(argc, sizeof(pval **));
- if (args == NULL) {
- RETURN_FALSE;
- }
if (zend_get_parameters_array_ex(argc, args) == FAILURE) {
efree((void *)args);
WRONG_PARAM_COUNT;
@@ -2508,96 +2499,9 @@ PHP_FUNCTION(mb_convert_variables)
from_encoding = mbfl_no_encoding_invalid;
stack_max = PHP_MBSTR_STACK_BLOCK_SIZE;
stack = (pval ***)emalloc(stack_max*sizeof(pval **));
- if (stack != NULL) {
- stack_level = 0;
- identd = mbfl_encoding_detector_new(elist, elistsz TSRMLS_CC);
- if (identd != NULL) {
- n = 2;
- while (n < argc || stack_level > 0) {
- if (stack_level <= 0) {
- var = args[n++];
- if (Z_TYPE_PP(var) == IS_ARRAY || Z_TYPE_PP(var) == IS_OBJECT) {
- target_hash = HASH_OF(*var);
- if (target_hash != NULL) {
- zend_hash_internal_pointer_reset(target_hash);
- }
- }
- } else {
- stack_level--;
- var = stack[stack_level];
- }
- if (Z_TYPE_PP(var) == IS_ARRAY || Z_TYPE_PP(var) == IS_OBJECT) {
- target_hash = HASH_OF(*var);
- if (target_hash != NULL) {
- while (zend_hash_get_current_data(target_hash, (void **) &hash_entry) != FAILURE) {
- zend_hash_move_forward(target_hash);
- if (Z_TYPE_PP(hash_entry) == IS_ARRAY || Z_TYPE_PP(hash_entry) == IS_OBJECT) {
- if (stack_level >= stack_max) {
- stack_max += PHP_MBSTR_STACK_BLOCK_SIZE;
- ptmp = erealloc(stack, sizeof(pval **)*stack_max);
- if (ptmp == NULL) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "stack err at %s:(%d)", __FILE__, __LINE__);
- continue;
- }
- stack = (pval ***)ptmp;
- }
- stack[stack_level] = var;
- stack_level++;
- var = hash_entry;
- target_hash = HASH_OF(*var);
- if (target_hash != NULL) {
- zend_hash_internal_pointer_reset(target_hash);
- continue;
- }
- } else if (Z_TYPE_PP(hash_entry) == IS_STRING) {
- string.val = (unsigned char *)Z_STRVAL_PP(hash_entry);
- string.len = Z_STRLEN_PP(hash_entry);
- if (mbfl_encoding_detector_feed(identd, &string TSRMLS_CC)) {
- goto detect_end; /* complete detecting */
- }
- }
- }
- }
- } else if (Z_TYPE_PP(var) == IS_STRING) {
- string.val = (unsigned char *)Z_STRVAL_PP(var);
- string.len = Z_STRLEN_PP(var);
- if (mbfl_encoding_detector_feed(identd, &string TSRMLS_CC)) {
- goto detect_end; /* complete detecting */
- }
- }
- }
-detect_end:
- from_encoding = mbfl_encoding_detector_judge(identd TSRMLS_CC);
- mbfl_encoding_detector_delete(identd TSRMLS_CC);
- }
- efree(stack);
- }
- if (from_encoding == mbfl_no_encoding_invalid) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to detect encoding");
- from_encoding = mbfl_no_encoding_pass;
- }
- }
- if (elist != NULL) {
- efree((void *)elist);
- }
- /* create converter */
- convd = NULL;
- if (from_encoding != mbfl_no_encoding_pass) {
- convd = mbfl_buffer_converter_new(from_encoding, to_encoding, 0 TSRMLS_CC);
- if (convd == NULL) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to create converter");
- RETURN_FALSE;
- }
- mbfl_buffer_converter_illegal_mode(convd, MBSTRG(current_filter_illegal_mode) TSRMLS_CC);
- mbfl_buffer_converter_illegal_substchar(convd, MBSTRG(current_filter_illegal_substchar) TSRMLS_CC);
- }
-
- /* convert */
- if (convd != NULL) {
- stack_max = PHP_MBSTR_STACK_BLOCK_SIZE;
- stack = (pval ***)emalloc(stack_max*sizeof(pval **));
- if (stack != NULL) {
- stack_level = 0;
+ stack_level = 0;
+ identd = mbfl_encoding_detector_new(elist, elistsz TSRMLS_CC);
+ if (identd != NULL) {
n = 2;
while (n < argc || stack_level > 0) {
if (stack_level <= 0) {
@@ -2621,10 +2525,6 @@ detect_end:
if (stack_level >= stack_max) {
stack_max += PHP_MBSTR_STACK_BLOCK_SIZE;
ptmp = erealloc(stack, sizeof(pval **)*stack_max);
- if (ptmp == NULL) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "stack err at %s:(%d)", __FILE__, __LINE__);
- continue;
- }
stack = (pval ***)ptmp;
}
stack[stack_level] = var;
@@ -2638,11 +2538,8 @@ detect_end:
} else if (Z_TYPE_PP(hash_entry) == IS_STRING) {
string.val = (unsigned char *)Z_STRVAL_PP(hash_entry);
string.len = Z_STRLEN_PP(hash_entry);
- ret = mbfl_buffer_converter_feed_result(convd, &string, &result TSRMLS_CC);
- if (ret != NULL) {
- STR_FREE(Z_STRVAL_PP(hash_entry));
- Z_STRVAL_PP(hash_entry) = (char *)ret->val;
- Z_STRLEN_PP(hash_entry) = ret->len;
+ if (mbfl_encoding_detector_feed(identd, &string TSRMLS_CC)) {
+ goto detect_end; /* complete detecting */
}
}
}
@@ -2650,16 +2547,100 @@ detect_end:
} else if (Z_TYPE_PP(var) == IS_STRING) {
string.val = (unsigned char *)Z_STRVAL_PP(var);
string.len = Z_STRLEN_PP(var);
- ret = mbfl_buffer_converter_feed_result(convd, &string, &result TSRMLS_CC);
- if (ret != NULL) {
- STR_FREE(Z_STRVAL_PP(var));
- Z_STRVAL_PP(var) = (char *)ret->val;
- Z_STRLEN_PP(var) = ret->len;
+ if (mbfl_encoding_detector_feed(identd, &string TSRMLS_CC)) {
+ goto detect_end; /* complete detecting */
+ }
+ }
+ }
+detect_end:
+ from_encoding = mbfl_encoding_detector_judge(identd TSRMLS_CC);
+ mbfl_encoding_detector_delete(identd TSRMLS_CC);
+ }
+ efree(stack);
+
+ if (from_encoding == mbfl_no_encoding_invalid) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to detect encoding");
+ from_encoding = mbfl_no_encoding_pass;
+ }
+ }
+ if (elist != NULL) {
+ efree((void *)elist);
+ }
+ /* create converter */
+ convd = NULL;
+ if (from_encoding != mbfl_no_encoding_pass) {
+ convd = mbfl_buffer_converter_new(from_encoding, to_encoding, 0 TSRMLS_CC);
+ if (convd == NULL) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to create converter");
+ RETURN_FALSE;
+ }
+ mbfl_buffer_converter_illegal_mode(convd, MBSTRG(current_filter_illegal_mode) TSRMLS_CC);
+ mbfl_buffer_converter_illegal_substchar(convd, MBSTRG(current_filter_illegal_substchar) TSRMLS_CC);
+ }
+
+ /* convert */
+ if (convd != NULL) {
+ stack_max = PHP_MBSTR_STACK_BLOCK_SIZE;
+ stack = (pval ***)emalloc(stack_max*sizeof(pval **));
+ stack_level = 0;
+ n = 2;
+ while (n < argc || stack_level > 0) {
+ if (stack_level <= 0) {
+ var = args[n++];
+ if (Z_TYPE_PP(var) == IS_ARRAY || Z_TYPE_PP(var) == IS_OBJECT) {
+ target_hash = HASH_OF(*var);
+ if (target_hash != NULL) {
+ zend_hash_internal_pointer_reset(target_hash);
}
}
+ } else {
+ stack_level--;
+ var = stack[stack_level];
+ }
+ if (Z_TYPE_PP(var) == IS_ARRAY || Z_TYPE_PP(var) == IS_OBJECT) {
+ target_hash = HASH_OF(*var);
+ if (target_hash != NULL) {
+ while (zend_hash_get_current_data(target_hash, (void **) &hash_entry) != FAILURE) {
+ zend_hash_move_forward(target_hash);
+ if (Z_TYPE_PP(hash_entry) == IS_ARRAY || Z_TYPE_PP(hash_entry) == IS_OBJECT) {
+ if (stack_level >= stack_max) {
+ stack_max += PHP_MBSTR_STACK_BLOCK_SIZE;
+ ptmp = erealloc(stack, sizeof(pval **)*stack_max);
+ stack = (pval ***)ptmp;
+ }
+ stack[stack_level] = var;
+ stack_level++;
+ var = hash_entry;
+ target_hash = HASH_OF(*var);
+ if (target_hash != NULL) {
+ zend_hash_internal_pointer_reset(target_hash);
+ continue;
+ }
+ } else if (Z_TYPE_PP(hash_entry) == IS_STRING) {
+ string.val = (unsigned char *)Z_STRVAL_PP(hash_entry);
+ string.len = Z_STRLEN_PP(hash_entry);
+ ret = mbfl_buffer_converter_feed_result(convd, &string, &result TSRMLS_CC);
+ if (ret != NULL) {
+ STR_FREE(Z_STRVAL_PP(hash_entry));
+ Z_STRVAL_PP(hash_entry) = (char *)ret->val;
+ Z_STRLEN_PP(hash_entry) = ret->len;
+ }
+ }
+ }
+ }
+ } else if (Z_TYPE_PP(var) == IS_STRING) {
+ string.val = (unsigned char *)Z_STRVAL_PP(var);
+ string.len = Z_STRLEN_PP(var);
+ ret = mbfl_buffer_converter_feed_result(convd, &string, &result TSRMLS_CC);
+ if (ret != NULL) {
+ STR_FREE(Z_STRVAL_PP(var));
+ Z_STRVAL_PP(var) = (char *)ret->val;
+ Z_STRLEN_PP(var) = ret->len;
+ }
}
- efree(stack);
}
+ efree(stack);
+
mbfl_buffer_converter_delete(convd TSRMLS_CC);
}
@@ -2719,19 +2700,17 @@ php_mb_numericentity_exec(INTERNAL_FUNCTION_PARAMETERS, int type)
i = zend_hash_num_elements(target_hash);
if (i > 0) {
convmap = (int *)emalloc(i*sizeof(int));
- if (convmap != NULL) {
- mapelm = convmap;
- mapsize = 0;
- while (i > 0) {
- if (zend_hash_get_current_data(target_hash, (void **) &hash_entry) == FAILURE) {
- break;
- }
- convert_to_long_ex(hash_entry);
- *mapelm++ = Z_LVAL_PP(hash_entry);
- mapsize++;
- i--;
- zend_hash_move_forward(target_hash);
+ mapelm = convmap;
+ mapsize = 0;
+ while (i > 0) {
+ if (zend_hash_get_current_data(target_hash, (void **) &hash_entry) == FAILURE) {
+ break;
}
+ convert_to_long_ex(hash_entry);
+ *mapelm++ = Z_LVAL_PP(hash_entry);
+ mapsize++;
+ i--;
+ zend_hash_move_forward(target_hash);
}
}
}
@@ -2937,9 +2916,7 @@ PHP_FUNCTION(mb_get_info)
convert_to_string_ex(type);
if (argc == 0 || !strcasecmp("all", Z_STRVAL_PP(type))) {
- if (array_init(return_value) == FAILURE) {
- RETURN_FALSE;
- }
+ array_init(return_value);
if ((name = (char *)mbfl_no_encoding2name(MBSTRG(current_internal_encoding))) != NULL) {
add_assoc_string(return_value, "internal_encoding", name, 1);
}
@@ -3083,15 +3060,9 @@ MBSTRING_API int php_mb_set_zend_encoding(TSRMLS_D)
list_size += strlen(name) + 1;
if (!list) {
list = (char*)emalloc(list_size);
- if (!list) {
- return -1;
- }
*list = (char)NULL;
} else {
list = (char*)erealloc(list, list_size);
- if (!list) {
- return -1;
- }
strcat(list, ",");
}
strcat(list, name);
diff --git a/ext/mbstring/php_mbregex.c b/ext/mbstring/php_mbregex.c
index c4b49eb7b0..ecf8183e34 100644
--- a/ext/mbstring/php_mbregex.c
+++ b/ext/mbstring/php_mbregex.c
@@ -238,20 +238,15 @@ php_mbregex_compile_pattern(mb_regex_t *pre, const char *pattern, int patlen, in
rc->options != options || rc->mbctype != mbctype) {
memset(pre, 0, sizeof(*pre));
pre->fastmap = (char*)emalloc((1 << MBRE_BYTEWIDTH)*sizeof(char));
- if (pre->fastmap) {
- pre->options = options;
- pre->mbctype = mbctype;
- err_str = mbre_compile_pattern(pattern, patlen, pre);
- if (!err_str) {
- zend_hash_update(&MBSTRG(ht_rc), (char *) pattern, patlen+1, (void *) pre, sizeof(*pre), NULL);
- } else {
- efree(pre->fastmap);
- pre->fastmap = (char*)0;
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "mbregex compile err: %s", err_str);
- res = 1;
- }
+ pre->options = options;
+ pre->mbctype = mbctype;
+ err_str = mbre_compile_pattern(pattern, patlen, pre);
+ if (!err_str) {
+ zend_hash_update(&MBSTRG(ht_rc), (char *) pattern, patlen+1, (void *) pre, sizeof(*pre), NULL);
} else {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to allocate memory in mbregex_compile_pattern");
+ efree(pre->fastmap);
+ pre->fastmap = (char*)0;
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "mbregex compile err: %s", err_str);
res = 1;
}
} else {
@@ -698,10 +693,6 @@ PHP_FUNCTION(mb_split)
if (count == 0) count = 1;
- if (array_init(return_value) == FAILURE) {
- RETURN_FALSE;
- }
-
/* create regex pattern buffer */
err = php_mbregex_compile_pattern(
&re,
@@ -712,6 +703,8 @@ PHP_FUNCTION(mb_split)
RETURN_FALSE;
}
+ array_init(return_value);
+
pos = 0;
err = 0;
/* churn through str, generating array entries as we go */
@@ -895,29 +888,23 @@ _php_mb_regex_ereg_search_exec(INTERNAL_FUNCTION_PARAMETERS, int mode)
}
switch (mode) {
case 1:
- if (array_init(return_value) != FAILURE) {
- beg = MBSTRG(search_regs)->beg[0];
- end = MBSTRG(search_regs)->end[0];
- add_next_index_long(return_value, beg);
- add_next_index_long(return_value, end - beg);
- } else {
- RETVAL_FALSE;
- }
+ array_init(return_value);
+ beg = MBSTRG(search_regs)->beg[0];
+ end = MBSTRG(search_regs)->end[0];
+ add_next_index_long(return_value, beg);
+ add_next_index_long(return_value, end - beg);
break;
case 2:
- if (array_init(return_value) != FAILURE) {
- n = MBSTRG(search_regs)->num_regs;
- for (i = 0; i < n; i++) {
- beg = MBSTRG(search_regs)->beg[i];
- end = MBSTRG(search_regs)->end[i];
- if (beg >= 0 && beg <= end && end <= len) {
- add_index_stringl(return_value, i, (char *)&str[beg], end - beg, 1);
- } else {
- add_index_bool(return_value, i, 0);
- }
+ array_init(return_value);
+ n = MBSTRG(search_regs)->num_regs;
+ for (i = 0; i < n; i++) {
+ beg = MBSTRG(search_regs)->beg[i];
+ end = MBSTRG(search_regs)->end[i];
+ if (beg >= 0 && beg <= end && end <= len) {
+ add_index_stringl(return_value, i, (char *)&str[beg], end - beg, 1);
+ } else {
+ add_index_bool(return_value, i, 0);
}
- } else {
- RETVAL_FALSE;
}
break;
default: