From 2fd82f7048ecd718b157ebc557e2d0424c9da097 Mon Sep 17 00:00:00 2001 From: Kent Gibson Date: Wed, 9 Sep 2020 09:40:03 +0800 Subject: [PATCH] bindings: cxx: fix event timestamp calculation for 32bit Use appropriate C++ chrono library functions to convert the event timestamp from a struct timespec to ::std::chrono::nanoseconds to ensure correct conversion independent of platform. Fixes: 8078a4a2ad90 ("bindings: implement C++ bindings") Reported-by: Florian Evers Signed-off-by: Kent Gibson Signed-off-by: Bartosz Golaszewski --- bindings/cxx/line.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bindings/cxx/line.cpp b/bindings/cxx/line.cpp index 11deae6..52084bf 100644 --- a/bindings/cxx/line.cpp +++ b/bindings/cxx/line.cpp @@ -215,8 +215,9 @@ line_event line::make_line_event(const ::gpiod_line_event& event) const noexcept else if (event.event_type == GPIOD_LINE_EVENT_FALLING_EDGE) ret.event_type = line_event::FALLING_EDGE; - ret.timestamp = ::std::chrono::nanoseconds( - event.ts.tv_nsec + (event.ts.tv_sec * 1000000000)); + ret.timestamp = ::std::chrono::duration_cast<::std::chrono::nanoseconds>( + ::std::chrono::seconds(event.ts.tv_sec)) + + ::std::chrono::nanoseconds(event.ts.tv_nsec); ret.source = *this; -- 2.30.2