From: Kent Gibson Date: Wed, 9 Sep 2020 01:40:03 +0000 (+0800) Subject: bindings: cxx: fix event timestamp calculation for 32bit X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=2fd82f7048ecd718b157ebc557e2d0424c9da097;p=qemu-gpiodev%2Flibgpiod.git 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 --- 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;