Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 58e1d79

Browse files
authored
Merge pull request #1019 from iyesin/make-hincrby-long-again
Fix integer overflow for long (>32bit) increments in hIncrBy
2 parents 6d104fc + aaffa7c commit 58e1d79

2 files changed

Lines changed: 4 additions & 1 deletion

File tree

redis_commands.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1412,7 +1412,7 @@ int redis_hincrby_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
14121412
key_free = redis_key_prefix(redis_sock, &key, (int *)&key_len);
14131413

14141414
// Construct command
1415-
*cmd_len = redis_cmd_format_static(cmd, "HINCRBY", "ssd", key, key_len, mem,
1415+
*cmd_len = redis_cmd_format_static(cmd, "HINCRBY", "ssl", key, key_len, mem,
14161416
mem_len, byval);
14171417
// Set slot
14181418
CMD_SET_SLOT(slot,key,key_len);

tests/RedisTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2290,6 +2290,8 @@ public function testHashes() {
22902290
$this->assertTrue(3 === $this->redis->hIncrBy('h', 'x', 1));
22912291
$this->assertTrue(2 === $this->redis->hIncrBy('h', 'x', -1));
22922292
$this->assertTrue("2" === $this->redis->hGet('h', 'x'));
2293+
$this->assertTrue(1000000000002 === $this->redis->hIncrBy('h', 'x', 1000000000000));
2294+
$this->assertTrue("1000000000002" === $this->redis->hGet('h', 'x'));
22932295

22942296
$this->redis->hSet('h', 'y', 'not-a-number');
22952297
$this->assertTrue(FALSE === $this->redis->hIncrBy('h', 'y', 1));
@@ -2300,6 +2302,7 @@ public function testHashes() {
23002302
$this->assertTrue(1.5 === $this->redis->hIncrByFloat('h','x', 1.5));
23012303
$this->assertTrue(3.0 === $this->redis->hincrByFloat('h','x', 1.5));
23022304
$this->assertTrue(1.5 === $this->redis->hincrByFloat('h','x', -1.5));
2305+
$this->assertTrue(1000000000001.5 === $this->redis->hincrByFloat('h','x', 1000000000000));
23032306

23042307
$this->redis->hset('h','y','not-a-number');
23052308
$this->assertTrue(FALSE === $this->redis->hIncrByFloat('h', 'y', 1.5));

0 commit comments

Comments
 (0)