Skip to content

Commit 7c67fc5

Browse files
committed
fixed checks
1 parent ee32e4d commit 7c67fc5

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

library.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2823,6 +2823,9 @@ static uint8_t crc8(unsigned char *input, size_t len) {
28232823
}
28242824
#endif
28252825

2826+
#define PHP_REDIS_COMPRESSION_RATIO_CHECK(__x) \
2827+
(redis_sock->compression_min_ratio > 0 && (((double) __x / (double) len) >= redis_sock->compression_min_ratio))
2828+
28262829
PHP_REDIS_API int
28272830
redis_pack(RedisSock *redis_sock, zval *z, char **val, size_t *val_len)
28282831
{
@@ -2849,7 +2852,7 @@ redis_pack(RedisSock *redis_sock, zval *z, char **val, size_t *val_len)
28492852
size = len + MIN(UINT_MAX - len, MAX(LZF_MARGIN, len / 25));
28502853
data = emalloc(size);
28512854
if ((res = lzf_compress(buf, len, data, size)) > 0) {
2852-
if (((double) res / (double) len) >= redis_sock->compression_min_ratio) {
2855+
if (PHP_REDIS_COMPRESSION_RATIO_CHECK(res)) {
28532856
efree(data);
28542857
break;
28552858
}
@@ -2884,7 +2887,7 @@ redis_pack(RedisSock *redis_sock, zval *z, char **val, size_t *val_len)
28842887
size = ZSTD_compressBound(len);
28852888
data = emalloc(size);
28862889
size = ZSTD_compress(data, size, buf, len, level);
2887-
if (!ZSTD_isError(size) && ((double) size / (double) len) < redis_sock->compression_min_ratio) {
2890+
if (!ZSTD_isError(size) && !PHP_REDIS_COMPRESSION_RATIO_CHECK(size)) {
28882891
if (valfree) efree(buf);
28892892
data = erealloc(data, size);
28902893
*val = data;

0 commit comments

Comments
 (0)