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
235f5534
Commit
235f5534
authored
Mar 02, 2016
by
Salvatore Sanfilippo
Browse files
Merge pull request #3118 from sunheehnus/bitfield-fix-minor-bug
bitops/bitfield: fix length, overflow condition and *sign
parents
e85d6f22
93cc8baf
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/bitops.c
View file @
235f5534
...
@@ -318,7 +318,8 @@ int checkSignedBitfieldOverflow(int64_t value, int64_t incr, uint64_t bits, int
...
@@ -318,7 +318,8 @@ int checkSignedBitfieldOverflow(int64_t value, int64_t incr, uint64_t bits, int
int64_t
maxincr
=
max
-
value
;
int64_t
maxincr
=
max
-
value
;
int64_t
minincr
=
min
-
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
(
limit
)
{
if
(
owtype
==
BFOVERFLOW_WRAP
)
{
if
(
owtype
==
BFOVERFLOW_WRAP
)
{
goto
handle_wrap
;
goto
handle_wrap
;
...
@@ -327,7 +328,8 @@ int checkSignedBitfieldOverflow(int64_t value, int64_t incr, uint64_t bits, int
...
@@ -327,7 +328,8 @@ int checkSignedBitfieldOverflow(int64_t value, int64_t incr, uint64_t bits, int
}
}
}
}
return
1
;
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
(
limit
)
{
if
(
owtype
==
BFOVERFLOW_WRAP
)
{
if
(
owtype
==
BFOVERFLOW_WRAP
)
{
goto
handle_wrap
;
goto
handle_wrap
;
...
@@ -445,8 +447,8 @@ int getBitfieldTypeFromArgument(client *c, robj *o, int *sign, int *bits) {
...
@@ -445,8 +447,8 @@ int getBitfieldTypeFromArgument(client *c, robj *o, int *sign, int *bits) {
if
((
string2ll
(
p
+
1
,
strlen
(
p
+
1
),
&
llbits
))
==
0
||
if
((
string2ll
(
p
+
1
,
strlen
(
p
+
1
),
&
llbits
))
==
0
||
llbits
<
1
||
llbits
<
1
||
(
*
sign
==
1
&&
llbits
>
6
3
)
||
(
*
sign
==
1
&&
llbits
>
6
4
)
||
(
*
sign
==
0
&&
llbits
>
6
4
))
(
*
sign
==
0
&&
llbits
>
6
3
))
{
{
addReplyError
(
c
,
err
);
addReplyError
(
c
,
err
);
return
C_ERR
;
return
C_ERR
;
...
@@ -963,7 +965,8 @@ void bitfieldCommand(client *c) {
...
@@ -963,7 +965,8 @@ void bitfieldCommand(client *c) {
* for simplicity. SET return value is the previous value so
* for simplicity. SET return value is the previous value so
* we need fetch & store as well. */
* 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
/* We need two different but very similar code paths for signed
* and unsigned operations, since the set of functions to get/set
* and unsigned operations, since the set of functions to get/set
...
...
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