diff options
author | Gary E. Miller <gem@rellim.com> | 2015-06-03 16:19:42 -0700 |
---|---|---|
committer | Gary E. Miller <gem@rellim.com> | 2015-06-03 16:19:42 -0700 |
commit | ebb1d9da881c31db7ef2db6ae017daa1238134fa (patch) | |
tree | 937ae4b5cfa052c6e2b0c1bb7228c97382a77e58 /ppsthread.h | |
parent | 7a04ef5ac5e96fb3ae989a98586776273215c953 (diff) | |
download | gpsd-ebb1d9da881c31db7ef2db6ae017daa1238134fa.tar.gz |
Fix overflow issue on 32 bit binaries.
Timespec is a 62 bit number, it does not fit in the 32 bits of
a long. Use 'long long' instead. 'long long' is always at least
64 bits long and is the same as a native int when compiled as 64 bit.
Note that many 64 bit OS still run 32 bit binaries, and many small
devices like RasPi's are 32 bit.
Diffstat (limited to 'ppsthread.h')
-rw-r--r-- | ppsthread.h | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/ppsthread.h b/ppsthread.h index 81faa033..58d4b31a 100644 --- a/ppsthread.h +++ b/ppsthread.h @@ -17,9 +17,9 @@ struct timedelta_t { #endif /* TIMEDELTA_DEFINED */ /* difference between timespecs in nanoseconds */ -/* int is too small, avoid floats */ -/* WARNING! this will overflow if x and y differ by more than a few seconds */ -#define timespec_diff_ns(x, y) (long)(((x).tv_sec-(y).tv_sec)*1000000000+(x).tv_nsec-(y).tv_nsec) +/* int is too small, 32 bit long is too small, avoid floats */ +/* MUST be long long to maintain precision on 32 bit code */ +#define timespec_diff_ns(x, y) (long long)(((x).tv_sec-(y).tv_sec)*1000000000LL+(x).tv_nsec-(y).tv_nsec) /* * Set context, devicefd, and devicename at initialization time, before |