Skip to content

Commit a392016

Browse files
author
Ilia Alshanetsky
committed
Catch empty strings right away.
1 parent 9b7ba01 commit a392016

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

ext/standard/string.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4851,32 +4851,38 @@ PHP_FUNCTION(str_word_count)
48514851
return;
48524852
}
48534853

4854-
if (char_list) {
4855-
php_charmask(char_list, char_list_len, ch TSRMLS_CC);
4856-
}
4857-
4858-
p = str;
4859-
e = str + str_len;
4860-
48614854
switch(type) {
48624855
case 1:
48634856
case 2:
48644857
array_init(return_value);
4858+
if (!str_len) {
4859+
return;
4860+
}
48654861
break;
48664862
case 0:
4863+
if (!str_len) {
4864+
RETURN_LONG(0);
4865+
}
48674866
/* nothing to be done */
48684867
break;
48694868
default:
48704869
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid format value %ld", type);
48714870
RETURN_FALSE;
48724871
}
48734872

4873+
if (char_list) {
4874+
php_charmask(char_list, char_list_len, ch TSRMLS_CC);
4875+
}
4876+
4877+
p = str;
4878+
e = str + str_len;
4879+
48744880
/* first character cannot be ' or -, unless explicitly allowed by the user */
48754881
if ((*p == '\'' && (!char_list || !ch['\''])) || (*p == '-' && (!char_list || !ch['-']))) {
48764882
p++;
48774883
}
48784884
/* last character cannot be -, unless explicitly allowed by the user */
4879-
if (str_len && *(e - 1) == '-' && (!char_list || !ch['-'])) {
4885+
if (*(e - 1) == '-' && (!char_list || !ch['-'])) {
48804886
e--;
48814887
}
48824888

0 commit comments

Comments
 (0)