Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
hiredis
Commits
fdc80234
Commit
fdc80234
authored
Jul 15, 2011
by
Pieter Noordhuis
Browse files
Fix type for nil objects
parent
4234b1cf
Changes
2
Show whitespace changes
Inline
Side-by-side
parser.c
View file @
fdc80234
...
@@ -330,6 +330,7 @@ size_t redis_parser_execute(redis_parser_t *parser, redis_protocol_t **dst, cons
...
@@ -330,6 +330,7 @@ size_t redis_parser_execute(redis_parser_t *parser, redis_protocol_t **dst, cons
if
(
cur
->
type
==
REDIS_STRING_T
)
{
if
(
cur
->
type
==
REDIS_STRING_T
)
{
if
(
i64
.
i64
<
0
)
{
/* nil bulk */
if
(
i64
.
i64
<
0
)
{
/* nil bulk */
cur
->
type
=
REDIS_NIL_T
;
CALLBACK
(
nil
,
cur
);
CALLBACK
(
nil
,
cur
);
goto
done
;
goto
done
;
}
}
...
@@ -346,6 +347,7 @@ size_t redis_parser_execute(redis_parser_t *parser, redis_protocol_t **dst, cons
...
@@ -346,6 +347,7 @@ size_t redis_parser_execute(redis_parser_t *parser, redis_protocol_t **dst, cons
if
(
cur
->
type
==
REDIS_ARRAY_T
)
{
if
(
cur
->
type
==
REDIS_ARRAY_T
)
{
if
(
i64
.
i64
<
0
)
{
/* nil multi bulk */
if
(
i64
.
i64
<
0
)
{
/* nil multi bulk */
cur
->
type
=
REDIS_NIL_T
;
CALLBACK
(
nil
,
cur
);
CALLBACK
(
nil
,
cur
);
goto
done
;
goto
done
;
}
}
...
...
test/parser.c
View file @
fdc80234
...
@@ -242,6 +242,25 @@ void test_empty_string(redis_parser_t *p) {
...
@@ -242,6 +242,25 @@ void test_empty_string(redis_parser_t *p) {
test_char_by_char
(
res
,
buf
,
len
);
test_char_by_char
(
res
,
buf
,
len
);
}
}
void
test_nil_string
(
redis_parser_t
*
p
)
{
const
char
*
buf
=
"$-1
\r\n
"
;
size_t
len
=
5
;
redis_protocol_t
*
res
;
/* Parse and check resulting protocol_t */
RESET_PARSER_T
(
p
);
assert_equal_size_t
(
redis_parser_execute
(
p
,
&
res
,
buf
,
len
),
len
);
assert
(
res
!=
NULL
);
assert_equal_size_t
(
res
->
type
,
REDIS_NIL_T
);
assert_equal_size_t
(
res
->
poff
,
0
);
assert_equal_size_t
(
res
->
plen
,
5
);
assert_equal_size_t
(
res
->
coff
,
0
);
assert_equal_size_t
(
res
->
clen
,
0
);
/* Chunked check */
test_char_by_char
(
res
,
buf
,
len
);
}
void
test_array
(
redis_parser_t
*
p
)
{
void
test_array
(
redis_parser_t
*
p
)
{
const
char
*
buf
=
const
char
*
buf
=
"*2
\r\n
"
"*2
\r\n
"
...
@@ -304,6 +323,23 @@ void test_empty_array(redis_parser_t *p) {
...
@@ -304,6 +323,23 @@ void test_empty_array(redis_parser_t *p) {
test_char_by_char
(
res
,
buf
,
len
);
test_char_by_char
(
res
,
buf
,
len
);
}
}
void
test_nil_array
(
redis_parser_t
*
p
)
{
const
char
*
buf
=
"*-1
\r\n
"
;
size_t
len
=
5
;
redis_protocol_t
*
res
;
/* Parse and check resulting protocol_t */
RESET_PARSER_T
(
p
);
assert_equal_size_t
(
redis_parser_execute
(
p
,
&
res
,
buf
,
len
),
len
);
assert
(
res
!=
NULL
);
assert_equal_size_t
(
res
->
type
,
REDIS_NIL_T
);
assert_equal_size_t
(
res
->
poff
,
0
);
assert_equal_size_t
(
res
->
plen
,
5
);
/* Chunked check */
test_char_by_char
(
res
,
buf
,
len
);
}
void
test_integer
(
redis_parser_t
*
p
)
{
void
test_integer
(
redis_parser_t
*
p
)
{
const
char
*
buf
=
":1234
\r\n
"
;
const
char
*
buf
=
":1234
\r\n
"
;
size_t
len
=
7
;
size_t
len
=
7
;
...
...
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