From 19e07776a627bfed098f28b36ff5becc686ebf55 Mon Sep 17 00:00:00 2001 From: alok Date: Wed, 11 Dec 2013 23:10:03 -0500 Subject: [PATCH 1/2] Fix unsigned/signed comparison warnings --- push.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/push.cpp b/push.cpp index 126e543..ecc8767 100644 --- a/push.cpp +++ b/push.cpp @@ -688,13 +688,13 @@ class CPushMod : public CModule /** * Check if the idle condition is met. * - * @return True if idle is zero or elapsed time is greater than idle + * @return True if idle is less than or equal to zero or elapsed time is greater than idle */ bool idle() { - unsigned int value = options["idle"].ToUInt(); + int value = options["idle"].ToInt(); time_t now = time(NULL); - return value == 0 + return value <= 0 || idle_time + value < now; } @@ -702,13 +702,13 @@ class CPushMod : public CModule * Check if the last_active condition is met. * * @param context Channel or nick context - * @return True if last_active is zero or elapsed time is greater than last_active + * @return True if last_active is less than or equal to zero or elapsed time is greater than last_active */ bool last_active(const CString& context) { - unsigned int value = options["last_active"].ToUInt(); + int value = options["last_active"].ToInt(); time_t now = time(NULL); - return value == 0 + return value <= 0 || last_active_time.count(context) < 1 || last_active_time[context] + value < now; } @@ -717,13 +717,13 @@ class CPushMod : public CModule * Check if the last_notification condition is met. * * @param context Channel or nick context - * @return True if last_notification is zero or elapsed time is greater than last_nofication + * @return True if last_notification is less than or equal to zero or elapsed time is greater than last_nofication */ bool last_notification(const CString& context) { - unsigned int value = options["last_notification"].ToUInt(); + int value = options["last_notification"].ToInt(); time_t now = time(NULL); - return value == 0 + return value <= 0 || last_notification_time.count(context) < 1 || last_notification_time[context] + value < now; } From d01ecd8cea64ea6a34f6c11837810fc80d1b804f Mon Sep 17 00:00:00 2001 From: alok Date: Thu, 12 Dec 2013 23:15:26 -0500 Subject: [PATCH 2/2] Use difftime to do time_t math This avoid any assumptions of what the underlying time_t type is. --- push.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/push.cpp b/push.cpp index ecc8767..d71e32e 100644 --- a/push.cpp +++ b/push.cpp @@ -692,10 +692,9 @@ class CPushMod : public CModule */ bool idle() { - int value = options["idle"].ToInt(); + unsigned int value = options["idle"].ToUInt(); time_t now = time(NULL); - return value <= 0 - || idle_time + value < now; + return value == 0 || difftime(now, idle_time) >= value; } /** @@ -706,11 +705,11 @@ class CPushMod : public CModule */ bool last_active(const CString& context) { - int value = options["last_active"].ToInt(); + unsigned int value = options["last_active"].ToUInt(); time_t now = time(NULL); - return value <= 0 + return value == 0 || last_active_time.count(context) < 1 - || last_active_time[context] + value < now; + || difftime(now, last_active_time[context]) >= value; } /** @@ -721,11 +720,11 @@ class CPushMod : public CModule */ bool last_notification(const CString& context) { - int value = options["last_notification"].ToInt(); + unsigned int value = options["last_notification"].ToUInt(); time_t now = time(NULL); - return value <= 0 + return value == 0 || last_notification_time.count(context) < 1 - || last_notification_time[context] + value < now; + || difftime(now, last_notification_time[context]) >= value; } /**