From: Harlan Stenn Date: Fri, 22 Jun 2007 05:01:28 +0000 (-0400) Subject: Start using 'design by contract' assertions X-Git-Tag: NTP_4_2_5P54~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=69d73e20aab4b0f27d69f6f8cdc9916521353e05;p=thirdparty%2Fntp.git Start using 'design by contract' assertions bk: 467b57a8Ct4HwqNtfH9gweCv797Xvg --- diff --git a/ChangeLog b/ChangeLog index 7fb7b5404..d2cb4c233 100644 --- 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. diff --git a/include/Makefile.am b/include/Makefile.am index 2f926e05b..eb4bd6232 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -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 index 000000000..7340548f1 --- /dev/null +++ b/include/ntp_assert.h @@ -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 diff --git a/libntp/atolfp.c b/libntp/atolfp.c index ff50947f0..adb67936f 100644 --- a/libntp/atolfp.c +++ b/libntp/atolfp.c @@ -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; diff --git a/libntp/prettydate.c b/libntp/prettydate.c index 55adf64ae..e9aa7d84d 100644 --- a/libntp/prettydate.c +++ b/libntp/prettydate.c @@ -7,6 +7,7 @@ #include "ntp_unixtime.h" /* includes */ #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!"