Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

DECRBY -2**63 over 0 should report out of range error #725

Open
jokea opened this Issue · 5 comments

3 participants

@jokea
redis 127.0.0.1:6379> set a 0
OK
redis 127.0.0.1:6379> decrby a -9223372036854775807
(integer) 9223372036854775807
redis 127.0.0.1:6379> set a 0
OK
redis 127.0.0.1:6379> decrby a -9223372036854775808
(integer) -9223372036854775808

The last decrby command should return out range error.

@anydot

Not and issue, minimal value for 64bit signed int really is "-9223372036854775808".

@jokea

That's true. But "0 - (-9223372036854775808)" should be 9223372036854775808,
which can't be represented as a signed 64bit value and should report out-of-range error.

@rootslab

https://github.com/antirez/redis/blob/unstable/src/t_string.c#L249

@jokea a little mod could solve it ( incrDecrCommand function )

 if ((incr < 0 && oldvalue <= 0 && incr < (LLONG_MIN-oldvalue+1)) ||
        (incr > 0 && oldvalue >= 0 && incr > (LLONG_MAX-oldvalue))) {
            ...
redis> set a 0
OK
redis> decrby a -9223372036854775808
(error) ERR increment or decrement would overflow
redis> get a
"0"

@jokea

Thanks @rootslab.

Fixing it is simple, I want to make sure this is a bug and gets fixed in all redis versions.

@rootslab

Hi @jokea,
since it's a minor bug/fix, I think it is useful to at least indicate the point in the code where it happens, or to send a simple pull request ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.