bindings: cxx: fix event timestamp calculation for 32bit
authorKent Gibson <warthog618@gmail.com>
Wed, 9 Sep 2020 01:40:03 +0000 (09:40 +0800)
committerBartosz Golaszewski <bgolaszewski@baylibre.com>
Mon, 14 Sep 2020 08:30:10 +0000 (10:30 +0200)
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 <florian-evers@gmx.de>
Signed-off-by: Kent Gibson <warthog618@gmail.com>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
bindings/cxx/line.cpp

index 11deae6f3720bf99300a16877323efde8a58f0db..52084bfc30636f3ed960fa0837327d963581655c 100644 (file)
@@ -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;