Skip to content

Commit

Permalink
ext/standard: Let is_numeric_str parse the int value for us in getopt()
Browse files Browse the repository at this point in the history
  • Loading branch information
Girgias committed Dec 29, 2024
1 parent aa1e5af commit 2a423af
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions ext/standard/basic_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -1071,16 +1071,16 @@ PHP_FUNCTION(getopt)

/* Add this option / argument pair to the result hash. */
optname_len = strlen(optname);
if (!(optname_len > 1 && optname[0] == '0') && is_numeric_string(optname, optname_len, NULL, NULL, 0) == IS_LONG) {
zend_long opt_name_as_long = 0;
if (!(optname_len > 1 && optname[0] == '0') && is_numeric_string(optname, optname_len, &opt_name_as_long, NULL, 0) == IS_LONG) {
/* numeric string */
int optname_int = atoi(optname);
if ((args = zend_hash_index_find(Z_ARRVAL_P(return_value), optname_int)) != NULL) {
if ((args = zend_hash_index_find(Z_ARRVAL_P(return_value), opt_name_as_long)) != NULL) {
if (Z_TYPE_P(args) != IS_ARRAY) {
convert_to_array(args);
}
zend_hash_next_index_insert(Z_ARRVAL_P(args), &val);
} else {
zend_hash_index_update(Z_ARRVAL_P(return_value), optname_int, &val);
zend_hash_index_update(Z_ARRVAL_P(return_value), opt_name_as_long, &val);
}
} else {
/* other strings */
Expand Down

0 comments on commit 2a423af

Please sign in to comment.