projects
/
redis.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
6e09ad1
)
Now HINCRBY can detect overflows too. Fix for issue #330.
author
antirez
<antirez@gmail.com>
Thu, 16 Feb 2012 15:09:08 +0000
(16:09 +0100)
committer
antirez
<antirez@gmail.com>
Thu, 16 Feb 2012 15:09:08 +0000
(16:09 +0100)
src/t_hash.c
patch
|
blob
|
blame
|
history
diff --git
a/src/t_hash.c
b/src/t_hash.c
index 8ee5485c1ad86f877d6f24e6bce98ca461f7f172..b8e2ad312d8508a8da332916e8c9b90b2f018ba8 100644
(file)
--- a/
src/t_hash.c
+++ b/
src/t_hash.c
@@
-320,7
+320,7
@@
void hmsetCommand(redisClient *c) {
}
void hincrbyCommand(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;
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;
}
value = 0;
}
+ oldvalue = value;
value += incr;
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);
new = createStringObjectFromLongLong(value);
hashTypeTryObjectEncoding(o,&c->argv[2],NULL);
hashTypeSet(o,c->argv[2],new);