overflow detection in INCR family functions

This commit is contained in:
antirez 2010-12-19 12:22:12 +01:00
parent 6418b4c790
commit 1443a814d0

View File

@ -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]);