From: Miroslav Lichvar Date: Wed, 2 Dec 2015 11:18:01 +0000 (+0100) Subject: main: assert supported integer size, representation and conversion X-Git-Tag: 2.3-pre1~80 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bafb434f068b35efcb9b1ffd6c8bb4198cd32eb5;p=thirdparty%2Fchrony.git main: assert supported integer size, representation and conversion 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. --- diff --git a/main.c b/main.c index 342704d8..e2cf4705 100644 --- 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 */