Skip to content

Commit 72ff907

Browse files
committed
ext/standard: Let is_numeric_str parse the int value for us in getopt()
1 parent f365510 commit 72ff907

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

ext/standard/basic_functions.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,16 +1071,16 @@ PHP_FUNCTION(getopt)
10711071

10721072
/* Add this option / argument pair to the result hash. */
10731073
optname_len = strlen(optname);
1074-
if (!(optname_len > 1 && optname[0] == '0') && is_numeric_string(optname, optname_len, NULL, NULL, 0) == IS_LONG) {
1074+
zend_long opt_name_as_long = 0;
1075+
if (!(optname_len > 1 && optname[0] == '0') && is_numeric_string(optname, optname_len, &opt_name_as_long, NULL, 0) == IS_LONG) {
10751076
/* numeric string */
1076-
int optname_int = atoi(optname);
1077-
if ((args = zend_hash_index_find(Z_ARRVAL_P(return_value), optname_int)) != NULL) {
1077+
if ((args = zend_hash_index_find(Z_ARRVAL_P(return_value), opt_name_as_long)) != NULL) {
10781078
if (Z_TYPE_P(args) != IS_ARRAY) {
10791079
convert_to_array(args);
10801080
}
10811081
zend_hash_next_index_insert(Z_ARRVAL_P(args), &val);
10821082
} else {
1083-
zend_hash_index_update(Z_ARRVAL_P(return_value), optname_int, &val);
1083+
zend_hash_index_update(Z_ARRVAL_P(return_value), opt_name_as_long, &val);
10841084
}
10851085
} else {
10861086
/* other strings */

0 commit comments

Comments
 (0)