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
7269d547
Commit
7269d547
authored
Feb 23, 2017
by
Salvatore Sanfilippo
Committed by
antirez
Mar 22, 2017
Browse files
Fix BITPOS unaligned memory access.
parent
15520588
Changes
1
Show whitespace changes
Inline
Side-by-side
src/bitops.c
View file @
7269d547
...
@@ -104,6 +104,7 @@ long redisBitpos(void *s, unsigned long count, int bit) {
...
@@ -104,6 +104,7 @@ long redisBitpos(void *s, unsigned long count, int bit) {
unsigned
long
skipval
,
word
=
0
,
one
;
unsigned
long
skipval
,
word
=
0
,
one
;
long
pos
=
0
;
/* Position of bit, to return to the caller. */
long
pos
=
0
;
/* Position of bit, to return to the caller. */
unsigned
long
j
;
unsigned
long
j
;
int
found
;
/* Process whole words first, seeking for first word that is not
/* Process whole words first, seeking for first word that is not
* all ones or all zeros respectively if we are lookig for zeros
* all ones or all zeros respectively if we are lookig for zeros
...
@@ -117,22 +118,28 @@ long redisBitpos(void *s, unsigned long count, int bit) {
...
@@ -117,22 +118,28 @@ long redisBitpos(void *s, unsigned long count, int bit) {
/* Skip initial bits not aligned to sizeof(unsigned long) byte by byte. */
/* Skip initial bits not aligned to sizeof(unsigned long) byte by byte. */
skipval
=
bit
?
0
:
UCHAR_MAX
;
skipval
=
bit
?
0
:
UCHAR_MAX
;
c
=
(
unsigned
char
*
)
s
;
c
=
(
unsigned
char
*
)
s
;
found
=
0
;
while
((
unsigned
long
)
c
&
(
sizeof
(
*
l
)
-
1
)
&&
count
)
{
while
((
unsigned
long
)
c
&
(
sizeof
(
*
l
)
-
1
)
&&
count
)
{
if
(
*
c
!=
skipval
)
break
;
if
(
*
c
!=
skipval
)
{
found
=
1
;
break
;
}
c
++
;
c
++
;
count
--
;
count
--
;
pos
+=
8
;
pos
+=
8
;
}
}
/* Skip bits with full word step. */
/* Skip bits with full word step. */
skipval
=
bit
?
0
:
ULONG_MAX
;
l
=
(
unsigned
long
*
)
c
;
l
=
(
unsigned
long
*
)
c
;
if
(
!
found
)
{
skipval
=
bit
?
0
:
ULONG_MAX
;
while
(
count
>=
sizeof
(
*
l
))
{
while
(
count
>=
sizeof
(
*
l
))
{
if
(
*
l
!=
skipval
)
break
;
if
(
*
l
!=
skipval
)
break
;
l
++
;
l
++
;
count
-=
sizeof
(
*
l
);
count
-=
sizeof
(
*
l
);
pos
+=
sizeof
(
*
l
)
*
8
;
pos
+=
sizeof
(
*
l
)
*
8
;
}
}
}
/* Load bytes into "word" considering the first byte as the most significant
/* Load bytes into "word" considering the first byte as the most significant
* (we basically consider it as written in big endian, since we consider the
* (we basically consider it as written in big endian, since we consider the
...
...
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