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
redis
Commits
9d7165e8
Commit
9d7165e8
authored
Dec 19, 2010
by
antirez
Browse files
overflow detection in INCR family functions
parent
59aee551
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/t_string.c
View file @
9d7165e8
...
@@ -346,14 +346,19 @@ void msetnxCommand(redisClient *c) {
...
@@ -346,14 +346,19 @@ void msetnxCommand(redisClient *c) {
}
}
void
incrDecrCommand
(
redisClient
*
c
,
long
long
incr
)
{
void
incrDecrCommand
(
redisClient
*
c
,
long
long
incr
)
{
long
long
value
;
long
long
value
,
oldvalue
;
robj
*
o
;
robj
*
o
;
o
=
lookupKeyWrite
(
c
->
db
,
c
->
argv
[
1
]);
o
=
lookupKeyWrite
(
c
->
db
,
c
->
argv
[
1
]);
if
(
o
!=
NULL
&&
checkType
(
c
,
o
,
REDIS_STRING
))
return
;
if
(
o
!=
NULL
&&
checkType
(
c
,
o
,
REDIS_STRING
))
return
;
if
(
getLongLongFromObjectOrReply
(
c
,
o
,
&
value
,
NULL
)
!=
REDIS_OK
)
return
;
if
(
getLongLongFromObjectOrReply
(
c
,
o
,
&
value
,
NULL
)
!=
REDIS_OK
)
return
;
oldvalue
=
value
;
value
+=
incr
;
value
+=
incr
;
if
((
incr
<
0
&&
value
>
oldvalue
)
||
(
incr
>
0
&&
value
<
oldvalue
))
{
addReplyError
(
c
,
"increment or decrement would overflow"
);
return
;
}
o
=
createStringObjectFromLongLong
(
value
);
o
=
createStringObjectFromLongLong
(
value
);
dbReplace
(
c
->
db
,
c
->
argv
[
1
],
o
);
dbReplace
(
c
->
db
,
c
->
argv
[
1
],
o
);
touchWatchedKey
(
c
->
db
,
c
->
argv
[
1
]);
touchWatchedKey
(
c
->
db
,
c
->
argv
[
1
]);
...
...
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