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
hiredis
Commits
410c24d2
Commit
410c24d2
authored
Oct 19, 2020
by
michael-grunder
Browse files
Fix off-by-one error in seekNewline
parent
bd7488d2
Changes
1
Hide whitespace changes
Inline
Side-by-side
read.c
View file @
410c24d2
...
@@ -123,21 +123,27 @@ static char *readBytes(redisReader *r, unsigned int bytes) {
...
@@ -123,21 +123,27 @@ static char *readBytes(redisReader *r, unsigned int bytes) {
/* Find pointer to \r\n. */
/* Find pointer to \r\n. */
static
char
*
seekNewline
(
char
*
s
,
size_t
len
)
{
static
char
*
seekNewline
(
char
*
s
,
size_t
len
)
{
char
*
_s
=
s
,
*
ret
;
char
*
ret
;
int
_len
=
len
-
1
;
/* Exclude the last character from the searched length because the found
/* We cannot match with fewer than 2 bytes */
* '\r' should be followed by a '\n' */
if
(
len
<
2
)
while
((
ret
=
memchr
(
_s
,
'\r'
,
_len
))
!=
NULL
)
{
return
NULL
;
/* Search up to len - 1 characters */
len
--
;
/* Look for the \r */
while
((
ret
=
memchr
(
s
,
'\r'
,
len
))
!=
NULL
)
{
if
(
ret
[
1
]
==
'\n'
)
{
if
(
ret
[
1
]
==
'\n'
)
{
/* Found. */
/* Found. */
break
;
break
;
}
}
/* Continue searching. */
/* Continue searching. */
ret
++
;
ret
++
;
_
len
-=
ret
-
_
s
;
len
-=
ret
-
s
;
_
s
=
ret
;
s
=
ret
;
}
}
return
ret
;
return
ret
;
}
}
...
...
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