diff options
author | Jim Meyering <meyering@fb.com> | 2017-10-27 21:28:47 -0700 |
---|---|---|
committer | Jim Meyering <meyering@fb.com> | 2017-10-29 14:50:15 -0700 |
commit | 59faabad3639d126adc929b22f45cfb5007fa999 (patch) | |
tree | b3ef8cc34a90eb441f53dc8db837814208980588 | |
parent | e369b04cca4da1534c98628b8ee4648bfca2bb3a (diff) | |
download | gnulib-59faabad3639d126adc929b22f45cfb5007fa999.tar.gz |
timespec.h: use "assure" to avoid a spurious warning
* lib/timespec.h: Include "assure.h" and use it to help
gcc7's -Wstrict-overflow avoid a false positive warning
for a use in coreutils' ls.c. Suggested by Paul Eggert in
https://lists.gnu.org/r/bug-gnulib/2017-10/msg00007.html
* modules/timespec (Depends-on): Add assure.
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | lib/timespec.h | 6 | ||||
-rw-r--r-- | modules/timespec | 1 |
3 files changed, 16 insertions, 0 deletions
@@ -1,3 +1,12 @@ +2017-10-27 Jim Meyering <meyering@fb.com> + + timespec.h: use "assure" to avoid a spurious warning + * lib/timespec.h: Include "assure.h" and use it to help + gcc7's -Wstrict-overflow avoid a false positive warning + for a use in coreutils' ls.c. Suggested by Paul Eggert in + https://lists.gnu.org/r/bug-gnulib/2017-10/msg00007.html + * modules/timespec (Depends-on): Add assure. + 2017-10-29 Bruno Haible <bruno@clisp.org> Avoid several test failures with traditional locales on Haiku. diff --git a/lib/timespec.h b/lib/timespec.h index 3831301578..61cfebbeaf 100644 --- a/lib/timespec.h +++ b/lib/timespec.h @@ -33,6 +33,8 @@ _GL_INLINE_HEADER_BEGIN extern "C" { #endif +#include "assure.h" + /* Resolution of timespec timestamps (in units per second), and log base 10 of the resolution. */ @@ -81,6 +83,10 @@ make_timespec (time_t s, long int ns) _GL_TIMESPEC_INLINE int _GL_ATTRIBUTE_PURE timespec_cmp (struct timespec a, struct timespec b) { + /* These assure calls teach gcc7 enough so that its + -Wstrict-overflow does not complain about the following code. */ + assure (-1 <= a.tv_nsec && a.tv_nsec <= 2 * TIMESPEC_RESOLUTION); + assure (-1 <= b.tv_nsec && b.tv_nsec <= 2 * TIMESPEC_RESOLUTION); return (a.tv_sec < b.tv_sec ? -1 : a.tv_sec > b.tv_sec ? 1 : (int) (a.tv_nsec - b.tv_nsec)); diff --git a/modules/timespec b/modules/timespec index d18d1464fa..01ab6add23 100644 --- a/modules/timespec +++ b/modules/timespec @@ -7,6 +7,7 @@ lib/timespec.c m4/timespec.m4 Depends-on: +assure extern-inline time |