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
5fc9229c
Commit
5fc9229c
authored
May 28, 2010
by
antirez
Browse files
Fixed ZINCR Nan bugs leading to server crash and added tests
parent
8a3b0d2d
Changes
2
Hide whitespace changes
Inline
Side-by-side
redis.c
View file @
5fc9229c
...
...
@@ -5734,6 +5734,11 @@ static void zaddGenericCommand(redisClient *c, robj *key, robj *ele, double scor
zset
*
zs
;
double
*
score
;
if
(
isnan
(
scoreval
))
{
addReplySds
(
c
,
sdsnew
(
"-ERR provide score is Not A Number (nan)
\r\n
"
));
return
;
}
zsetobj
=
lookupKeyWrite
(
c
->
db
,
key
);
if
(
zsetobj
==
NULL
)
{
zsetobj
=
createZsetObject
();
...
...
@@ -5762,6 +5767,15 @@ static void zaddGenericCommand(redisClient *c, robj *key, robj *ele, double scor
}
else
{
*
score
=
scoreval
;
}
if
(
isnan
(
*
score
))
{
addReplySds
(
c
,
sdsnew
(
"-ERR resulting score is Not A Number (nan)
\r\n
"
));
zfree
(
score
);
/* Note that we don't need to check if the zset may be empty and
* should be removed here, as we can only obtain Nan as score if
* there was already an element in the sorted set. */
return
;
}
}
else
{
*
score
=
scoreval
;
}
...
...
tests/unit/type/zset.tcl
View file @
5fc9229c
...
...
@@ -397,4 +397,23 @@ start_server default.conf {} {
}
set _ $err
}
{}
test
{
ZSET element can't be set to nan with ZADD
}
{
set e
{}
catch
{
r zadd myzset nan abc
}
e
set _ $e
}
{
*Not A Number*
}
test
{
ZSET element can't be set to nan with ZINCRBY
}
{
set e
{}
catch
{
r zincrby myzset nan abc
}
e
set _ $e
}
{
*Not A Number*
}
test
{
ZINCRBY calls leading to Nan are refused
}
{
set e
{}
r zincrby myzset +inf abc
catch
{
r zincrby myzset -inf abc
}
e
set _ $e
}
{
*Not A Number*
}
}
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