ext/standard: Let is_numeric_str parse the int value for us in getopt()

This commit is contained in:
Gina Peter Banyard 2024-12-29 10:11:33 +00:00
parent f3655100b8
commit 72ff9077a5

View file

@ -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 */