]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
main: add assertions for timespec signedness
authorMiroslav Lichvar <mlichvar@redhat.com>
Tue, 23 Nov 2021 13:41:08 +0000 (14:41 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Wed, 24 Nov 2021 10:17:24 +0000 (11:17 +0100)
Some of the code (e.g. util and clientlog) may work with negative
values. Require that time_t and the tv_nsec types are signed. This seems
to be the case on all supported systems, but it it is not required by
POSIX.

main.c

diff --git a/main.c b/main.c
index 355cdc3a238162baa95e0ed85952c55c29bd4c1d..6a9463fe1b9136e947676947f4405e6b135b5a59 100644 (file)
--- a/main.c
+++ b/main.c
@@ -76,11 +76,18 @@ static REF_Mode ref_mode = REF_ModeNormal;
 static void
 do_platform_checks(void)
 {
+  struct timespec ts;
+
   /* Require at least 32-bit integers, two's complement representation and
      the usual implementation of conversion of unsigned integers */
   assert(sizeof (int) >= 4);
   assert(-1 == ~0);
   assert((int32_t)4294967295U == (int32_t)-1);
+
+  /* Require time_t and tv_nsec in timespec to be signed */
+  ts.tv_sec = -1;
+  ts.tv_nsec = -1;
+  assert(ts.tv_sec < 0 && ts.tv_nsec < 0);
 }
 
 /* ================================================== */