mirror of
http://github.com/valkey-io/valkey
synced 2024-11-22 00:52:38 +00:00
overflow detection in INCR family functions
This commit is contained in:
parent
6418b4c790
commit
1443a814d0
@ -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]);
|
||||
|
Loading…
Reference in New Issue
Block a user