Skip to content

Commit

Permalink
Modules: Fix an integer sign bug in moduleTimerHandler (redis#8131)
Browse files Browse the repository at this point in the history
bug was introduced in 1a91a27
  • Loading branch information
guybe7 authored Dec 3, 2020
1 parent 441c490 commit 2f41a38
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -5469,8 +5469,11 @@ int moduleTimerHandler(struct aeEventLoop *eventLoop, long long id, void *client
} else {
/* We call ustime() again instead of using the cached 'now' so that
* 'next_period' isn't affected by the time it took to execute
* previous calls to 'callback. */
next_period = (expiretime-ustime())/1000; /* Scale to milliseconds. */
* previous calls to 'callback.
* We need to cast 'expiretime' so that the compiler will not treat
* the difference as unsigned (Causing next_period to be huge) in
* case expiretime < ustime() */
next_period = ((long long)expiretime-ustime())/1000; /* Scale to milliseconds. */
break;
}
}
Expand Down Expand Up @@ -5519,7 +5522,8 @@ RedisModuleTimerID RM_CreateTimer(RedisModuleCtx *ctx, mstime_t period, RedisMod

/* We need to install the main event loop timer if it's not already
* installed, or we may need to refresh its period if we just installed
* a timer that will expire sooner than any other else. */
* a timer that will expire sooner than any other else (i.e. the timer
* we just installed is the first timer in the Timers rax). */
if (aeTimer != -1) {
raxIterator ri;
raxStart(&ri,Timers);
Expand Down

0 comments on commit 2f41a38

Please sign in to comment.