]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
Start using 'design by contract' assertions
authorHarlan Stenn <stenn@ntp.org>
Fri, 22 Jun 2007 05:01:28 +0000 (01:01 -0400)
committerHarlan Stenn <stenn@ntp.org>
Fri, 22 Jun 2007 05:01:28 +0000 (01:01 -0400)
bk: 467b57a8Ct4HwqNtfH9gweCv797Xvg

ChangeLog
include/Makefile.am
include/ntp_assert.h [new file with mode: 0644]
libntp/atolfp.c
libntp/prettydate.c

index 7fb7b54042cc81145af62bedfef7f91e6fc2a90f..d2cb4c233748cd48247586b9a8d6345e7afe67fa 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,4 @@
+* Start using 'design by contract' assertions.
 * Allow null driftfile.
 * More leap second fixes from Dave Mills.
 * Use YYERROR_VERBOSE for the new parser, and fix related BUILT_SOURCES.
index 2f926e05b653b5e1323c63f8ac7b4f789a9e8098..eb4bd62325dd68d203cd5bf17e06d90116361bad 100644 (file)
@@ -22,6 +22,7 @@ noinst_HEADERS = \
        mx4200.h \
        ntif.h \
        ntp.h \
+       ntp_assert.h \
        ntp_calendar.h \
        ntp_cmdargs.h \
        ntp_config.h \
diff --git a/include/ntp_assert.h b/include/ntp_assert.h
new file mode 100644 (file)
index 0000000..7340548
--- /dev/null
@@ -0,0 +1,15 @@
+/*
+ * ntp_assert.h - design by contract stuff
+ */
+
+#ifndef NTP_ASSSERT_H
+#define NTP_ASSERT_H
+
+#include "isc/assertions.h"
+
+#define NTP_REQUIRE(x) ISC_REQUIRE(x)
+#define NTP_INSIST(x)  ISC_INSIST(x)
+#define NTP_INVARIANT(x) ISC_INVARIANT(x)
+#define NTP_ENSURE(x)  ISC_ENSURE(x)
+
+#endif
index ff50947f0c4747353b7e22ecb22738fddc8a90f8..adb67936fe44466179a1344694b84b2e10a7dc39 100644 (file)
@@ -6,6 +6,7 @@
 
 #include "ntp_fp.h"
 #include "ntp_string.h"
+#include "ntp_assert.h"
 
 /*
  * Powers of 10
@@ -38,6 +39,8 @@ atolfp(
        int isneg;
        static const char *digits = "0123456789";
 
+       NTP_REQUIRE(str != NULL);
+
        isneg = 0;
        dec_i = dec_f = 0;
        ndec = 0;
index 55adf64aeeb25f226ab5d7eb74d41b95252bb8f5..e9aa7d84d22efc42bcbbc2572d67cdaeff211fb9 100644 (file)
@@ -7,6 +7,7 @@
 #include "ntp_unixtime.h"      /* includes <sys/time.h> */
 #include "lib_strbuf.h"
 #include "ntp_stdlib.h"
+#include "ntp_assert.h"
 
 static const char *months[] = {
   "Jan", "Feb", "Mar", "Apr", "May", "Jun",
@@ -52,6 +53,7 @@ ntp2unix_tm(
        */
     for (epoch_nr = 0; epoch_nr < MAX_EPOCH_NR; epoch_nr++) {
                tm = local ? localtime(&t) : gmtime(&t);
+               NTP_INSIST(tm != NULL);
 
 #if SIZEOF_TIME_T < 4
 # include "Bletch: sizeof(time_t) < 4!"