Attempt to fix an overflow bug in ZADD on Windows

Theory: In 64 bit windows `long` is 32 bits wide meaning that using a
long to append `ZADD` scores can truncate.

Possible fix for #2697
This commit is contained in:
michael-grunder
2025-09-03 14:08:02 -07:00
committed by Michael Grunder
parent 25e6d5fcc2
commit 35df8ad7c2
3 changed files with 10 additions and 2 deletions

View File

@@ -1072,8 +1072,15 @@ int redis_cmd_append_sstr_int(smart_string *str, int append) {
* Append a long to a smart string command * Append a long to a smart string command
*/ */
int redis_cmd_append_sstr_long(smart_string *str, long append) { int redis_cmd_append_sstr_long(smart_string *str, long append) {
return redis_cmd_append_sstr_zend_long(str, (zend_long) append);
}
/*
* Append a zend_long to a smart string command
*/
int redis_cmd_append_sstr_zend_long(smart_string *str, zend_long lval) {
char long_buf[32]; char long_buf[32];
char *result = zend_print_long_to_buf(long_buf + sizeof(long_buf) - 1, append); char *result = zend_print_long_to_buf(long_buf + sizeof(long_buf) - 1, lval);
int int_len = long_buf + sizeof(long_buf) - 1 - result; int int_len = long_buf + sizeof(long_buf) - 1 - result;
return redis_cmd_append_sstr(str, result, int_len); return redis_cmd_append_sstr(str, result, int_len);
} }

View File

@@ -50,6 +50,7 @@ int redis_cmd_init_sstr(smart_string *str, int num_args, char *keyword, int keyw
int redis_cmd_append_sstr(smart_string *str, char *append, int append_len); int redis_cmd_append_sstr(smart_string *str, char *append, int append_len);
int redis_cmd_append_sstr_int(smart_string *str, int append); int redis_cmd_append_sstr_int(smart_string *str, int append);
int redis_cmd_append_sstr_long(smart_string *str, long append); int redis_cmd_append_sstr_long(smart_string *str, long append);
int redis_cmd_append_sstr_zend_long(smart_string *str, zend_long append);
int redis_cmd_append_sstr_i64(smart_string *str, int64_t append); int redis_cmd_append_sstr_i64(smart_string *str, int64_t append);
int redis_cmd_append_sstr_u64(smart_string *str, uint64_t append); int redis_cmd_append_sstr_u64(smart_string *str, uint64_t append);
int redis_cmd_append_sstr_dbl(smart_string *str, double value); int redis_cmd_append_sstr_dbl(smart_string *str, double value);

View File

@@ -1208,7 +1208,7 @@ static int redis_cmd_append_sstr_score(smart_string *dst, zval *score) {
cmdlen = dst->len; cmdlen = dst->len;
if (Z_TYPE_P(score) == IS_LONG) { if (Z_TYPE_P(score) == IS_LONG) {
redis_cmd_append_sstr_long(dst, Z_LVAL_P(score)); redis_cmd_append_sstr_zend_long(dst, Z_LVAL_P(score));
} else if (Z_TYPE_P(score) == IS_DOUBLE) { } else if (Z_TYPE_P(score) == IS_DOUBLE) {
redis_cmd_append_sstr_dbl(dst, Z_DVAL_P(score)); redis_cmd_append_sstr_dbl(dst, Z_DVAL_P(score));
} else if (Z_TYPE_P(score) == IS_STRING) { } else if (Z_TYPE_P(score) == IS_STRING) {