summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSalvatore Sanfilippo <antirez@gmail.com>2016-03-02 15:12:38 +0100
committerSalvatore Sanfilippo <antirez@gmail.com>2016-03-02 15:12:38 +0100
commit235f55344b2474eaac0951a6183b79edb6be739a (patch)
tree9caee9d8ee9e6e4c7245fe109fb332298f8cf9f5 /src
parente85d6f22cf2ddb2a4a5de80b211802bdacbf4a3b (diff)
parent93cc8baf1ae5e3d028b4847b711b07c7e20cef4c (diff)
downloadredis-235f55344b2474eaac0951a6183b79edb6be739a.tar.gz
Merge pull request #3118 from sunheehnus/bitfield-fix-minor-bug
bitops/bitfield: fix length, overflow condition and *sign
Diffstat (limited to 'src')
-rw-r--r--src/bitops.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/bitops.c b/src/bitops.c
index 51f9cc00f..28405a3bf 100644
--- a/src/bitops.c
+++ b/src/bitops.c
@@ -318,7 +318,8 @@ int checkSignedBitfieldOverflow(int64_t value, int64_t incr, uint64_t bits, int
int64_t maxincr = max-value;
int64_t minincr = min-value;
- if (value > max || (value >= 0 && incr > 0 && incr > maxincr)) {
+ if (value > max || (bits == 64 && value >= 0 && incr > 0 && incr > maxincr)
+ || (bits < 64 && incr > 0 && incr > maxincr)) {
if (limit) {
if (owtype == BFOVERFLOW_WRAP) {
goto handle_wrap;
@@ -327,7 +328,8 @@ int checkSignedBitfieldOverflow(int64_t value, int64_t incr, uint64_t bits, int
}
}
return 1;
- } else if (value < min || (value < 0 && incr < 0 && incr < minincr)) {
+ } else if (value < min || (bits == 64 && value < 0 && incr < 0 && incr < minincr)
+ || (bits < 64 && incr < 0 && incr < minincr)) {
if (limit) {
if (owtype == BFOVERFLOW_WRAP) {
goto handle_wrap;
@@ -445,8 +447,8 @@ int getBitfieldTypeFromArgument(client *c, robj *o, int *sign, int *bits) {
if ((string2ll(p+1,strlen(p+1),&llbits)) == 0 ||
llbits < 1 ||
- (*sign == 1 && llbits > 63) ||
- (*sign == 0 && llbits > 64))
+ (*sign == 1 && llbits > 64) ||
+ (*sign == 0 && llbits > 63))
{
addReplyError(c,err);
return C_ERR;
@@ -963,7 +965,8 @@ void bitfieldCommand(client *c) {
* for simplicity. SET return value is the previous value so
* we need fetch & store as well. */
- if ((o = lookupStringForBitCommand(c,bitoffset)) == NULL) return;
+ if ((o = lookupStringForBitCommand(c,thisop->offset + thisop->bits))
+ == NULL) return;
/* We need two different but very similar code paths for signed
* and unsigned operations, since the set of functions to get/set