Skip to content

Commit ac9ec44

Browse files
committed
Merge branch 'issue.1166' into develop
2 parents 47d3722 + ba0070d commit ac9ec44

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

redis_commands.c

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -700,16 +700,6 @@ int redis_zinter_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
700700
// Process our weights
701701
ZEND_HASH_FOREACH_VAL(ht_weights, z_ele) {
702702
// Ignore non numeric args unless they're inf/-inf
703-
if (Z_TYPE_P(z_ele) != IS_LONG && Z_TYPE_P(z_ele) != IS_DOUBLE &&
704-
strncasecmp(Z_STRVAL_P(z_ele), "inf", sizeof("inf")) != 0 &&
705-
strncasecmp(Z_STRVAL_P(z_ele), "-inf", sizeof("-inf")) != 0 &&
706-
strncasecmp(Z_STRVAL_P(z_ele), "+inf", sizeof("+inf")) != 0
707-
) {
708-
php_error_docref(NULL TSRMLS_CC, E_WARNING,
709-
"Weights must be numeric or '-inf','inf','+inf'");
710-
efree(cmdstr.c);
711-
return FAILURE;
712-
}
713703

714704
switch (Z_TYPE_P(z_ele)) {
715705
case IS_LONG:
@@ -718,10 +708,30 @@ int redis_zinter_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
718708
case IS_DOUBLE:
719709
redis_cmd_append_sstr_dbl(&cmdstr, Z_DVAL_P(z_ele));
720710
break;
721-
case IS_STRING:
722-
redis_cmd_append_sstr(&cmdstr, Z_STRVAL_P(z_ele),
723-
Z_STRLEN_P(z_ele));
724-
break;
711+
case IS_STRING: {
712+
double dval;
713+
zend_long lval;
714+
zend_uchar type = is_numeric_string(Z_STRVAL_P(z_ele), Z_STRLEN_P(z_ele), &lval, &dval, 0);
715+
if (type == IS_LONG) {
716+
redis_cmd_append_sstr_long(&cmdstr, lval);
717+
break;
718+
} else if (type == IS_DOUBLE) {
719+
redis_cmd_append_sstr_dbl(&cmdstr, dval);
720+
break;
721+
} else if (strncasecmp(Z_STRVAL_P(z_ele), "-inf", sizeof("-inf") - 1) == 0 ||
722+
strncasecmp(Z_STRVAL_P(z_ele), "+inf", sizeof("+inf") - 1) == 0 ||
723+
strncasecmp(Z_STRVAL_P(z_ele), "inf", sizeof("inf") - 1) == 0
724+
) {
725+
redis_cmd_append_sstr(&cmdstr, Z_STRVAL_P(z_ele), Z_STRLEN_P(z_ele));
726+
break;
727+
}
728+
// fall through
729+
}
730+
default:
731+
php_error_docref(NULL TSRMLS_CC, E_WARNING,
732+
"Weights must be numeric or '-inf','inf','+inf'");
733+
efree(cmdstr.c);
734+
return FAILURE;
725735
}
726736
} ZEND_HASH_FOREACH_END();
727737
}

0 commit comments

Comments
 (0)