From 2e72d795a99e0bca4b517507d35680e20b64a444 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Fri, 30 Oct 2020 21:31:13 +0000 Subject: [PATCH] Fix timeout conversion error. --- config.mk | 2 +- lib/loop.c | 20 +++++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/config.mk b/config.mk index 05b1a898..4bd74923 100644 --- a/config.mk +++ b/config.mk @@ -139,7 +139,7 @@ ifeq ($(UNAME),SunOS) CFLAGS?=-Wall -ggdb -O2 endif else - CFLAGS?=-Wall -ggdb -O2 + CFLAGS?=-Wall -ggdb -O2 -Wconversion endif STATIC_LIB_DEPS:= diff --git a/lib/loop.c b/lib/loop.c index d9f207f8..a5c939cf 100644 --- a/lib/loop.c +++ b/lib/loop.c @@ -50,6 +50,7 @@ int mosquitto_loop(struct mosquitto *mosq, int timeout, int max_packets) #ifdef WITH_SRV int state; #endif + time_t timeout_ms; if(!mosq || max_packets < 1) return MOSQ_ERR_INVAL; #ifndef WIN32 @@ -109,26 +110,27 @@ int mosquitto_loop(struct mosquitto *mosq, int timeout, int max_packets) } } - if(timeout < 0){ - timeout = 1000; + timeout_ms = timeout; + if(timeout_ms < 0){ + timeout_ms = 1000; } now = mosquitto_time(); - if(mosq->next_msg_out && now + timeout/1000 > mosq->next_msg_out){ - timeout = (mosq->next_msg_out - now)*1000; + if(mosq->next_msg_out && now + timeout_ms/1000 > mosq->next_msg_out){ + timeout_ms = (mosq->next_msg_out - now)*1000; } - if(timeout < 0){ + if(timeout_ms < 0){ /* There has been a delay somewhere which means we should have already * sent a message. */ - timeout = 0; + timeout_ms = 0; } - local_timeout.tv_sec = timeout/1000; + local_timeout.tv_sec = timeout_ms/1000; #ifdef HAVE_PSELECT - local_timeout.tv_nsec = (timeout-local_timeout.tv_sec*1000)*1000000; + local_timeout.tv_nsec = (timeout_ms-local_timeout.tv_sec*1000)*1000000; #else - local_timeout.tv_usec = (timeout-local_timeout.tv_sec*1000)*1000; + local_timeout.tv_usec = (timeout_ms-local_timeout.tv_sec*1000)*1000; #endif #ifdef HAVE_PSELECT