]> Savannah Git Hosting - gnulib.git/commitdiff
timespec.h: use "assure" to avoid a spurious warning
authorJim Meyering <meyering@fb.com>
Sat, 28 Oct 2017 04:28:47 +0000 (21:28 -0700)
committerJim Meyering <meyering@fb.com>
Sun, 29 Oct 2017 21:50:15 +0000 (14:50 -0700)
* 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.

ChangeLog
lib/timespec.h
modules/timespec

index 7fa915f929a4b38f04cc6505a1b6a792d26a8555..26c56b17daa6327372690384ebb5696ae9370143 100644 (file)
--- 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.
index 3831301578ecd33ac5e14d439bc4081260be333c..61cfebbeaf43f92b8153035fdab5443597256af1 100644 (file)
@@ -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));
index d18d1464fa0b838087ae835b25bd1340a6d129ae..01ab6add23133890c6322f5da2edbd36e5e2df43 100644 (file)
@@ -7,6 +7,7 @@ lib/timespec.c
 m4/timespec.m4
 
 Depends-on:
+assure
 extern-inline
 time