From 565133411988dd6bd65dd6f56758cd96d689fec6 Mon Sep 17 00:00:00 2001 From: Kieran Bingham Date: Thu, 17 Jan 2019 16:13:38 +0000 Subject: libcamera: timer: Fix 32 bit wrap The msec parameter was multiplied as a 32 bit value when converting to nanosecond resolution. This wraps at 4.2949 seconds, and causes timers longer than this to fail. Fix the multiplication to upcast to 64 bit using an unsigned long long specifier on the multiplier. While we're here, initialise the two integer class members in the constructor initialiser list. Fixes: 1a57bcb8d1a7 ("libcamera: Add event notification infrastructure") Reviewed-by: Laurent Pinchart Signed-off-by: Kieran Bingham --- src/libcamera/timer.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/libcamera/timer.cpp b/src/libcamera/timer.cpp index b5212ba2..306825fd 100644 --- a/src/libcamera/timer.cpp +++ b/src/libcamera/timer.cpp @@ -36,6 +36,7 @@ namespace libcamera { * \brief Construct a timer */ Timer::Timer() + : interval_(0), deadline_(0) { } @@ -51,7 +52,7 @@ void Timer::start(unsigned int msec) clock_gettime(CLOCK_MONOTONIC, &tp); interval_ = msec; - deadline_ = tp.tv_sec * 1000000000ULL + tp.tv_nsec + msec * 1000000; + deadline_ = tp.tv_sec * 1000000000ULL + tp.tv_nsec + msec * 1000000ULL; LOG(Debug) << "Starting timer " << this << " with interval " << msec << ": deadline " << deadline_; -- cgit v1.2.1