]> sigrok.org Git - libserialport.git/commitdiff
windows: Fix warnings for conversions in time_as_timeval().
authorMartin Ling <redacted>
Fri, 24 Jan 2020 04:55:32 +0000 (04:55 +0000)
committerUwe Hermann <redacted>
Sun, 26 Jan 2020 20:11:37 +0000 (21:11 +0100)
Building with MSVC gave:

warning C4244: '=': conversion from 'LONGLONG' to 'long', possible loss of data

when assigning the results of these calculation to the long fields
of struct timeval. The result should be OK, but put an explicit
cast in to make the change clear and suppress the warning.

timing.c

index 8817e485fd0ea1f212e3625a3f1ca0b169e1b387..3a5f5c73086d6e61fd292d5e7653c984cf42fe66 100644 (file)
--- a/timing.c
+++ b/timing.c
@@ -89,9 +89,9 @@ SP_PRIV void time_as_timeval(const struct time *time, struct timeval *tv)
 #ifdef _WIN32
        LARGE_INTEGER frequency;
        QueryPerformanceFrequency(&frequency);
-       tv->tv_sec = time->ticks / frequency.QuadPart;
-       tv->tv_usec = (time->ticks % frequency.QuadPart) /
-               (frequency.QuadPart / 1000000);
+       tv->tv_sec = (long) (time->ticks / frequency.QuadPart);
+       tv->tv_usec = (long) ((time->ticks % frequency.QuadPart) /
+               (frequency.QuadPart / 1000000));
 #else
        *tv = time->tv;
 #endif