summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Meyering <meyering@fb.com>2017-10-27 21:28:47 -0700
committerJim Meyering <meyering@fb.com>2017-10-29 14:50:15 -0700
commit59faabad3639d126adc929b22f45cfb5007fa999 (patch)
treeb3ef8cc34a90eb441f53dc8db837814208980588
parente369b04cca4da1534c98628b8ee4648bfca2bb3a (diff)
downloadgnulib-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--ChangeLog9
-rw-r--r--lib/timespec.h6
-rw-r--r--modules/timespec1
3 files changed, 16 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 7fa915f929..26c56b17da 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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