Fix some static analysis warnings

Former-commit-id: 42a8f22c21706f9ddcaa63ceafc5ad817c1fe876
This commit is contained in:
John Sully 2019-12-27 18:17:22 -05:00
parent 8f20fc7f33
commit 55cddbe82f
3 changed files with 11 additions and 8 deletions

View File

@ -84,7 +84,7 @@ fastlock g_lock("AE (global)");
#endif #endif
thread_local aeEventLoop *g_eventLoopThisThread = NULL; thread_local aeEventLoop *g_eventLoopThisThread = NULL;
#define AE_ASSERT(x) if (!(x)) do { fprintf(stderr, "AE_ASSERT FAILURE %s: %d\n", __FILE__, __LINE__); *((volatile int*)0) = 1; } while(0) #define AE_ASSERT(x) if (!(x)) do { fprintf(stderr, "AE_ASSERT FAILURE %s: %d\n", __FILE__, __LINE__); *((volatile int*)1) = 1; } while(0)
/* Include the best multiplexing layer supported by this system. /* Include the best multiplexing layer supported by this system.
* The following should be ordered by performances, descending. */ * The following should be ordered by performances, descending. */
@ -237,11 +237,11 @@ int aeCreateRemoteFileEvent(aeEventLoop *eventLoop, int fd, int mask,
cmd.clientData = clientData; cmd.clientData = clientData;
cmd.pctl = nullptr; cmd.pctl = nullptr;
if (fSynchronous) if (fSynchronous)
{
cmd.pctl = new (MALLOC_LOCAL) aeCommandControl(); cmd.pctl = new (MALLOC_LOCAL) aeCommandControl();
std::unique_lock<std::mutex> ulock(cmd.pctl->mutexcv, std::defer_lock);
if (fSynchronous)
cmd.pctl->mutexcv.lock(); cmd.pctl->mutexcv.lock();
}
auto size = safe_write(eventLoop->fdCmdWrite, &cmd, sizeof(cmd)); auto size = safe_write(eventLoop->fdCmdWrite, &cmd, sizeof(cmd));
if (size != sizeof(cmd)) if (size != sizeof(cmd))
{ {
@ -252,6 +252,7 @@ int aeCreateRemoteFileEvent(aeEventLoop *eventLoop, int fd, int mask,
if (fSynchronous) if (fSynchronous)
{ {
std::unique_lock<std::mutex> ulock(cmd.pctl->mutexcv, std::defer_lock);
cmd.pctl->cv.wait(ulock); cmd.pctl->cv.wait(ulock);
ret = cmd.pctl->rval; ret = cmd.pctl->rval;
delete cmd.pctl; delete cmd.pctl;
@ -289,15 +290,17 @@ int aePostFunction(aeEventLoop *eventLoop, std::function<void()> fn, bool fSynch
cmd.pfn = new (MALLOC_LOCAL) std::function<void()>(fn); cmd.pfn = new (MALLOC_LOCAL) std::function<void()>(fn);
cmd.pctl = nullptr; cmd.pctl = nullptr;
if (fSynchronous) if (fSynchronous)
{
cmd.pctl = new (MALLOC_LOCAL) aeCommandControl(); cmd.pctl = new (MALLOC_LOCAL) aeCommandControl();
std::unique_lock<std::mutex> ulock(cmd.pctl->mutexcv, std::defer_lock);
if (fSynchronous)
cmd.pctl->mutexcv.lock(); cmd.pctl->mutexcv.lock();
}
auto size = write(eventLoop->fdCmdWrite, &cmd, sizeof(cmd)); auto size = write(eventLoop->fdCmdWrite, &cmd, sizeof(cmd));
AE_ASSERT(size == sizeof(cmd)); AE_ASSERT(size == sizeof(cmd));
int ret = AE_OK; int ret = AE_OK;
if (fSynchronous) if (fSynchronous)
{ {
std::unique_lock<std::mutex> ulock(cmd.pctl->mutexcv, std::defer_lock);
cmd.pctl->cv.wait(ulock); cmd.pctl->cv.wait(ulock);
ret = cmd.pctl->rval; ret = cmd.pctl->rval;
delete cmd.pctl; delete cmd.pctl;

View File

@ -1919,7 +1919,7 @@ int rdbLoadRio(rio *rdb, rdbSaveInfo *rsi, int loading_aof) {
redisDb *db = g_pserver->db+0; redisDb *db = g_pserver->db+0;
char buf[1024]; char buf[1024];
/* Key-specific attributes, set by opcodes before the key type. */ /* Key-specific attributes, set by opcodes before the key type. */
long long lru_idle = -1, lfu_freq = -1, expiretime = -1, now = mstime(); long long lru_idle = -1, lfu_freq = -1, expiretime = -1, now;
long long lru_clock = 0; long long lru_clock = 0;
uint64_t mvcc_tstamp = OBJ_MVCC_INVALID; uint64_t mvcc_tstamp = OBJ_MVCC_INVALID;
robj *subexpireKey = nullptr; robj *subexpireKey = nullptr;

View File

@ -3061,7 +3061,7 @@ void replicationCron(void) {
} }
/* Timed out master when we are an already connected replica? */ /* Timed out master when we are an already connected replica? */
if (mi->masterhost && mi->repl_state == REPL_STATE_CONNECTED && if (mi->masterhost && mi->master && mi->repl_state == REPL_STATE_CONNECTED &&
(time(NULL)-mi->master->lastinteraction) > g_pserver->repl_timeout) (time(NULL)-mi->master->lastinteraction) > g_pserver->repl_timeout)
{ {
serverLog(LL_WARNING,"MASTER timeout: no data nor PING received..."); serverLog(LL_WARNING,"MASTER timeout: no data nor PING received...");