mirror of
https://codeberg.org/redict/redict.git
synced 2025-01-22 16:18:28 -05:00
Fixed undefined behavior in *INCR style functions overflow detection. Sorry clang!
This commit is contained in:
parent
fe7be46025
commit
7c96b467c1
@ -337,11 +337,12 @@ void hincrbyCommand(redisClient *c) {
|
||||
}
|
||||
|
||||
oldvalue = value;
|
||||
value += incr;
|
||||
if ((incr < 0 && value > oldvalue) || (incr > 0 && value < oldvalue)) {
|
||||
if ((incr < 0 && oldvalue < 0 && incr < (LLONG_MIN-oldvalue)) ||
|
||||
(incr > 0 && oldvalue > 0 && incr > (LLONG_MAX-oldvalue))) {
|
||||
addReplyError(c,"increment or decrement would overflow");
|
||||
return;
|
||||
}
|
||||
value += incr;
|
||||
new = createStringObjectFromLongLong(value);
|
||||
hashTypeTryObjectEncoding(o,&c->argv[2],NULL);
|
||||
hashTypeSet(o,c->argv[2],new);
|
||||
|
@ -344,11 +344,12 @@ void incrDecrCommand(redisClient *c, long long incr) {
|
||||
if (getLongLongFromObjectOrReply(c,o,&value,NULL) != REDIS_OK) return;
|
||||
|
||||
oldvalue = value;
|
||||
value += incr;
|
||||
if ((incr < 0 && value > oldvalue) || (incr > 0 && value < oldvalue)) {
|
||||
if ((incr < 0 && oldvalue < 0 && incr < (LLONG_MIN-oldvalue)) ||
|
||||
(incr > 0 && oldvalue > 0 && incr > (LLONG_MAX-oldvalue))) {
|
||||
addReplyError(c,"increment or decrement would overflow");
|
||||
return;
|
||||
}
|
||||
value += incr;
|
||||
new = createStringObjectFromLongLong(value);
|
||||
if (o)
|
||||
dbOverwrite(c->db,c->argv[1],new);
|
||||
|
Loading…
Reference in New Issue
Block a user