From 3e293e285757b4c96f857505d8ba8d0efcc13ceb Mon Sep 17 00:00:00 2001 From: Hans-Joachim Krauch Date: Tue, 1 May 2018 18:45:41 +0200 Subject: [PATCH 1/3] Fix integer overflow for oneshot timers. --- clients/roscpp/include/ros/timer_manager.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clients/roscpp/include/ros/timer_manager.h b/clients/roscpp/include/ros/timer_manager.h index 27cc346386..7974cc24a2 100644 --- a/clients/roscpp/include/ros/timer_manager.h +++ b/clients/roscpp/include/ros/timer_manager.h @@ -584,7 +584,7 @@ void TimerManager::threadFunc() { // On system time we can simply sleep for the rest of the wait time, since anything else requiring processing will // signal the condition variable - int32_t remaining_time = std::max((int32_t)((sleep_end - current).toSec() * 1000.0f), 1); + int64_t remaining_time = std::max((int64_t)((sleep_end - current).toSec() * 1000.0f), (int64_t)1); timers_cond_.timed_wait(lock, boost::posix_time::milliseconds(remaining_time)); } } From 32c66cf0da1cd3bba0aca88bae966c835fab5bbf Mon Sep 17 00:00:00 2001 From: Hans-Joachim Krauch Date: Thu, 10 May 2018 12:42:20 +0200 Subject: [PATCH 2/3] Use static_cast instead of c-style cast. --- clients/roscpp/include/ros/timer_manager.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clients/roscpp/include/ros/timer_manager.h b/clients/roscpp/include/ros/timer_manager.h index 7974cc24a2..b785a85729 100644 --- a/clients/roscpp/include/ros/timer_manager.h +++ b/clients/roscpp/include/ros/timer_manager.h @@ -584,7 +584,7 @@ void TimerManager::threadFunc() { // On system time we can simply sleep for the rest of the wait time, since anything else requiring processing will // signal the condition variable - int64_t remaining_time = std::max((int64_t)((sleep_end - current).toSec() * 1000.0f), (int64_t)1); + int64_t remaining_time = static_cast(std::max((sleep_end - current).toSec() * 1000.0f, 1.0)); timers_cond_.timed_wait(lock, boost::posix_time::milliseconds(remaining_time)); } } From 5616fb2b3fcdc4c4075108d9e2e28a901568d794 Mon Sep 17 00:00:00 2001 From: Hans-Joachim Krauch Date: Thu, 10 May 2018 18:52:25 +0200 Subject: [PATCH 3/3] Template std::max instead of casting explicitely. --- clients/roscpp/include/ros/timer_manager.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clients/roscpp/include/ros/timer_manager.h b/clients/roscpp/include/ros/timer_manager.h index b785a85729..2264ee91fb 100644 --- a/clients/roscpp/include/ros/timer_manager.h +++ b/clients/roscpp/include/ros/timer_manager.h @@ -584,7 +584,7 @@ void TimerManager::threadFunc() { // On system time we can simply sleep for the rest of the wait time, since anything else requiring processing will // signal the condition variable - int64_t remaining_time = static_cast(std::max((sleep_end - current).toSec() * 1000.0f, 1.0)); + int64_t remaining_time = std::max((sleep_end - current).toSec() * 1000.0f, 1); timers_cond_.timed_wait(lock, boost::posix_time::milliseconds(remaining_time)); } }