]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
main: assert supported integer size, representation and conversion
authorMiroslav Lichvar <mlichvar@redhat.com>
Wed, 2 Dec 2015 11:18:01 +0000 (12:18 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Thu, 3 Dec 2015 10:43:06 +0000 (11:43 +0100)
Abort immediately on start if chronyd is compiled on a platform with int
shorter than 32 bits, using other representation than two's complement,
or unexpected conversion of large unsigned integers to signed.

main.c

diff --git a/main.c b/main.c
index 342704d80f15cc28a53261e34746198743216483..e2cf4705d9089acf8360d8261f1348b46cb4185f 100644 (file)
--- a/main.c
+++ b/main.c
@@ -68,6 +68,18 @@ static REF_Mode ref_mode = REF_ModeNormal;
 
 /* ================================================== */
 
+static void
+do_platform_checks(void)
+{
+  /* 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)4294967295 == (int32_t)-1);
+}
+
+/* ================================================== */
+
 static void
 delete_pidfile(void)
 {
@@ -351,6 +363,8 @@ int main
   int system_log = 1;
   int config_args = 0;
 
+  do_platform_checks();
+
   LOG_Initialise();
 
   /* Parse command line options */