X-Git-Url: https://git.saurik.com/redis.git/blobdiff_plain/ad1b4f4f59e653ac310ee0afb847daeb4f19fbfd..697af434fbeb2e3ba2ba9687cd283ed1a2734fa5:/src/t_string.c diff --git a/src/t_string.c b/src/t_string.c index eb080c88..c3e3607f 100644 --- a/src/t_string.c +++ b/src/t_string.c @@ -346,14 +346,19 @@ void msetnxCommand(redisClient *c) { } void incrDecrCommand(redisClient *c, long long incr) { - long long value; + long long value, oldvalue; robj *o; o = lookupKeyWrite(c->db,c->argv[1]); if (o != NULL && checkType(c,o,REDIS_STRING)) return; if (getLongLongFromObjectOrReply(c,o,&value,NULL) != REDIS_OK) return; + oldvalue = value; value += incr; + if ((incr < 0 && value > oldvalue) || (incr > 0 && value < oldvalue)) { + addReplyError(c,"increment or decrement would overflow"); + return; + } o = createStringObjectFromLongLong(value); dbReplace(c->db,c->argv[1],o); touchWatchedKey(c->db,c->argv[1]);