Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
32289d57
Commit
32289d57
authored
Feb 29, 2016
by
antirez
Browse files
BITFIELD: refactoring & fix of retval on FAIL.
parent
11745e09
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/bitops.c
View file @
32289d57
...
...
@@ -965,8 +965,11 @@ void bitfieldCommand(client *c) {
if
((
o
=
lookupStringForBitCommand
(
c
,
bitoffset
))
==
NULL
)
return
;
/* We need two different but very similar code paths for signed
* and unsigned operations, since the set of functions to get/set
* the integers and the used variables types are different. */
if
(
thisop
->
sign
)
{
int64_t
oldval
,
newval
,
wrapped
;
int64_t
oldval
,
newval
,
wrapped
,
retval
;
int
overflow
;
oldval
=
getSignedBitfield
(
o
->
ptr
,
thisop
->
offset
,
...
...
@@ -977,21 +980,26 @@ void bitfieldCommand(client *c) {
overflow
=
checkSignedBitfieldOverflow
(
oldval
,
thisop
->
i64
,
thisop
->
bits
,
thisop
->
owtype
,
&
wrapped
);
if
(
overflow
)
newval
=
wrapped
;
addReplyLongLong
(
c
,
newval
)
;
retval
=
newval
;
}
else
{
newval
=
thisop
->
i64
;
overflow
=
checkSignedBitfieldOverflow
(
newval
,
0
,
thisop
->
bits
,
thisop
->
owtype
,
&
wrapped
);
if
(
overflow
)
newval
=
wrapped
;
addReplyLongLong
(
c
,
oldval
)
;
retval
=
oldval
;
}
/* If the overflow type is "FAIL", don't write. */
/* On overflow of type is "FAIL", don't write and return
* NULL to signal the condition. */
if
(
!
(
overflow
&&
thisop
->
owtype
==
BFOVERFLOW_FAIL
))
{
addReplyLongLong
(
c
,
retval
);
setSignedBitfield
(
o
->
ptr
,
thisop
->
offset
,
thisop
->
bits
,
newval
);
}
else
{
addReply
(
c
,
shared
.
nullbulk
);
}
}
else
{
uint64_t
oldval
,
newval
,
wrapped
;
uint64_t
oldval
,
newval
,
wrapped
,
retval
;
int
overflow
;
oldval
=
getUnsignedBitfield
(
o
->
ptr
,
thisop
->
offset
,
...
...
@@ -1002,15 +1010,23 @@ void bitfieldCommand(client *c) {
overflow
=
checkUnsignedBitfieldOverflow
(
oldval
,
thisop
->
i64
,
thisop
->
bits
,
thisop
->
owtype
,
&
wrapped
);
if
(
overflow
)
newval
=
wrapped
;
addReplyLongLong
(
c
,
newval
)
;
retval
=
newval
;
}
else
{
newval
=
thisop
->
i64
;
overflow
=
checkUnsignedBitfieldOverflow
(
newval
,
0
,
thisop
->
bits
,
thisop
->
owtype
,
&
wrapped
);
if
(
overflow
)
newval
=
wrapped
;
addReplyLongLong
(
c
,
oldval
);
retval
=
oldval
;
}
/* On overflow of type is "FAIL", don't write and return
* NULL to signal the condition. */
if
(
!
(
overflow
&&
thisop
->
owtype
==
BFOVERFLOW_FAIL
))
{
addReplyLongLong
(
c
,
retval
);
setUnsignedBitfield
(
o
->
ptr
,
thisop
->
offset
,
thisop
->
bits
,
newval
);
}
else
{
addReply
(
c
,
shared
.
nullbulk
);
}
setUnsignedBitfield
(
o
->
ptr
,
thisop
->
offset
,
thisop
->
bits
,
newval
);
}
changes
++
;
}
else
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment