mirror of
https://github.com/php-win-ext/phpredis.git
synced 2026-03-24 00:52:16 +01:00
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:
committed by
Michael Grunder
parent
25e6d5fcc2
commit
35df8ad7c2
@@ -1072,8 +1072,15 @@ int redis_cmd_append_sstr_int(smart_string *str, int append) {
|
||||
* Append a long to a smart string command
|
||||
*/
|
||||
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 *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;
|
||||
return redis_cmd_append_sstr(str, result, int_len);
|
||||
}
|
||||
|
||||
@@ -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_int(smart_string *str, int 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_u64(smart_string *str, uint64_t append);
|
||||
int redis_cmd_append_sstr_dbl(smart_string *str, double value);
|
||||
|
||||
@@ -1208,7 +1208,7 @@ static int redis_cmd_append_sstr_score(smart_string *dst, zval *score) {
|
||||
cmdlen = dst->len;
|
||||
|
||||
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) {
|
||||
redis_cmd_append_sstr_dbl(dst, Z_DVAL_P(score));
|
||||
} else if (Z_TYPE_P(score) == IS_STRING) {
|
||||
|
||||
Reference in New Issue
Block a user