Skip to content

Commit 5c4fe08

Browse files
generic_z_command fixes
Use the lengths for our optional parameters, as NULL will come through as a non null zval pointer with a zero length Properly return the length from the redis_cmd_sstr_init function
1 parent 6e0f0d7 commit 5c4fe08

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

library.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,7 @@ int redis_cmd_init_sstr(smart_str *str, int num_args, char *keyword, int keyword
467467
smart_str_appendl(str, _NL, sizeof(_NL) - 1);
468468
smart_str_appendl(str, keyword, keyword_len);
469469
smart_str_appendl(str, _NL, sizeof(_NL) - 1);
470+
return str->len;
470471
}
471472

472473
/*

redis.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4405,7 +4405,7 @@ PHPAPI void generic_z_command(INTERNAL_FUNCTION_PARAMETERS, char *command, int c
44054405
}
44064406

44074407
// AGGREGATE option
4408-
if(agg_op != NULL) {
4408+
if(agg_op_len != 0) {
44094409
// Verify our aggregation option
44104410
if(strncasecmp(agg_op, "SUM", sizeof("SUM")) &&
44114411
strncasecmp(agg_op, "MIN", sizeof("MIN")) &&
@@ -4470,7 +4470,7 @@ PHPAPI void generic_z_command(INTERNAL_FUNCTION_PARAMETERS, char *command, int c
44704470
// Weights
44714471
if(ht_weights != NULL) {
44724472
// Append "WEIGHTS" argument
4473-
redis_cmd_append_sstr(&cmd, "WEIGHTS", sizeof("WEIGHTS"));
4473+
redis_cmd_append_sstr(&cmd, "WEIGHTS", sizeof("WEIGHTS") - 1);
44744474

44754475
// Process weights
44764476
for(zend_hash_internal_pointer_reset_ex(ht_weights, &ptr);
@@ -4489,7 +4489,7 @@ PHPAPI void generic_z_command(INTERNAL_FUNCTION_PARAMETERS, char *command, int c
44894489
RETURN_FALSE;
44904490
}
44914491

4492-
// Append the weight based on it's input type
4492+
// Append the weight based on the input type
44934493
switch(Z_TYPE_PP(z_data)) {
44944494
case IS_LONG:
44954495
redis_cmd_append_sstr_long(&cmd, Z_LVAL_PP(z_data));
@@ -4505,8 +4505,8 @@ PHPAPI void generic_z_command(INTERNAL_FUNCTION_PARAMETERS, char *command, int c
45054505
}
45064506

45074507
// Aggregation options, if we have them
4508-
if(agg_op) {
4509-
redis_cmd_append_sstr(&cmd, "AGGREGATE", sizeof("AGGREGATE"));
4508+
if(agg_op_len != 0) {
4509+
redis_cmd_append_sstr(&cmd, "AGGREGATE", sizeof("AGGREGATE") - 1);
45104510
redis_cmd_append_sstr(&cmd, agg_op, agg_op_len);
45114511
}
45124512

0 commit comments

Comments
 (0)