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
74629731
Commit
74629731
authored
Jun 22, 2020
by
antirez
Browse files
Fix BITFIELD i64 type handling, see #7417.
parent
59fd1780
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/bitops.c
View file @
74629731
...
@@ -257,7 +257,7 @@ int64_t getSignedBitfield(unsigned char *p, uint64_t offset, uint64_t bits) {
...
@@ -257,7 +257,7 @@ int64_t getSignedBitfield(unsigned char *p, uint64_t offset, uint64_t bits) {
/* If the top significant bit is 1, propagate it to all the
/* If the top significant bit is 1, propagate it to all the
* higher bits for two's complement representation of signed
* higher bits for two's complement representation of signed
* integers. */
* integers. */
if
(
value
&
((
uint64_t
)
1
<<
(
bits
-
1
)))
if
(
bits
<
64
&&
(
value
&
((
uint64_t
)
1
<<
(
bits
-
1
)))
)
value
|=
((
uint64_t
)
-
1
)
<<
bits
;
value
|=
((
uint64_t
)
-
1
)
<<
bits
;
return
value
;
return
value
;
}
}
...
@@ -356,7 +356,6 @@ int checkSignedBitfieldOverflow(int64_t value, int64_t incr, uint64_t bits, int
...
@@ -356,7 +356,6 @@ int checkSignedBitfieldOverflow(int64_t value, int64_t incr, uint64_t bits, int
handle_wrap:
handle_wrap:
{
{
uint64_t
mask
=
((
uint64_t
)
-
1
)
<<
bits
;
uint64_t
msb
=
(
uint64_t
)
1
<<
(
bits
-
1
);
uint64_t
msb
=
(
uint64_t
)
1
<<
(
bits
-
1
);
uint64_t
a
=
value
,
b
=
incr
,
c
;
uint64_t
a
=
value
,
b
=
incr
,
c
;
c
=
a
+
b
;
/* Perform addition as unsigned so that's defined. */
c
=
a
+
b
;
/* Perform addition as unsigned so that's defined. */
...
@@ -364,10 +363,13 @@ handle_wrap:
...
@@ -364,10 +363,13 @@ handle_wrap:
/* If the sign bit is set, propagate to all the higher order
/* If the sign bit is set, propagate to all the higher order
* bits, to cap the negative value. If it's clear, mask to
* bits, to cap the negative value. If it's clear, mask to
* the positive integer limit. */
* the positive integer limit. */
if
(
c
&
msb
)
{
if
(
bits
<
64
)
{
c
|=
mask
;
uint64_t
mask
=
((
uint64_t
)
-
1
)
<<
bits
;
}
else
{
if
(
c
&
msb
)
{
c
&=
~
mask
;
c
|=
mask
;
}
else
{
c
&=
~
mask
;
}
}
}
*
limit
=
c
;
*
limit
=
c
;
}
}
...
...
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