From a400a9b2d753fcfc90aa234019ab7afd21966509 Mon Sep 17 00:00:00 2001 From: antirez Date: Thu, 16 Feb 2012 16:09:08 +0100 Subject: [PATCH] Now HINCRBY can detect overflows too. Fix for issue #330. --- src/t_hash.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/t_hash.c b/src/t_hash.c index 8ee5485c..b8e2ad31 100644 --- a/src/t_hash.c +++ b/src/t_hash.c @@ -320,7 +320,7 @@ void hmsetCommand(redisClient *c) { } void hincrbyCommand(redisClient *c) { - long long value, incr; + long long value, incr, oldvalue; robj *o, *current, *new; if (getLongLongFromObjectOrReply(c,c->argv[3],&incr,NULL) != REDIS_OK) return; @@ -336,7 +336,12 @@ void hincrbyCommand(redisClient *c) { value = 0; } + oldvalue = value; value += incr; + if ((incr < 0 && value > oldvalue) || (incr > 0 && value < oldvalue)) { + addReplyError(c,"increment or decrement would overflow"); + return; + } new = createStringObjectFromLongLong(value); hashTypeTryObjectEncoding(o,&c->argv[2],NULL); hashTypeSet(o,c->argv[2],new); -- 2.47.2