From f9cb0a92ff41fb37ec3cbe4933f651757b2fae90 Mon Sep 17 00:00:00 2001 From: Marcus Winter Date: Mon, 7 Mar 2016 11:23:25 +0100 Subject: [PATCH] base_c: fixed checks and documentation in time, duration and log --- base_c/include/embb/base/c/duration.h | 2 ++ base_c/include/embb/base/c/log.h | 1 + base_c/include/embb/base/c/time.h | 2 ++ base_c/src/duration.c | 9 ++------- base_c/src/log.c | 2 ++ base_c/src/time.c | 9 ++------- 6 files changed, 11 insertions(+), 14 deletions(-) diff --git a/base_c/include/embb/base/c/duration.h b/base_c/include/embb/base/c/duration.h index 1af05db..7f943fb 100644 --- a/base_c/include/embb/base/c/duration.h +++ b/base_c/include/embb/base/c/duration.h @@ -249,6 +249,8 @@ int embb_duration_as_seconds( /** * Compares two durations. * + * \pre \c lhs and \c rhs are not NULL and properly initialized. + * * \return -1 if \c lhs < \c rhs \n * 0 if \c lhs == \c rhs \n * 1 if \c lhs > \c rhs diff --git a/base_c/include/embb/base/c/log.h b/base_c/include/embb/base/c/log.h index 31c5128..bf73dc5 100644 --- a/base_c/include/embb/base/c/log.h +++ b/base_c/include/embb/base/c/log.h @@ -67,6 +67,7 @@ typedef void(*embb_log_function_t)(void * context, char const * message); /** * Default logging function. * Writes to the given file (context needs to be a FILE*). + * \pre \c context is not NULL. * \ingroup C_LOG * \threadsafe */ diff --git a/base_c/include/embb/base/c/time.h b/base_c/include/embb/base/c/time.h index 3316253..e4f1d18 100644 --- a/base_c/include/embb/base/c/time.h +++ b/base_c/include/embb/base/c/time.h @@ -89,6 +89,8 @@ int embb_time_in( /** * Compares two time points. * + * \pre \c lhs and \c rhs are not NULL and properly initialized. + * * \return -1 if \c lhs < \c rhs \n * 0 if \c lhs == \c rhs \n * 1 if \c lhs > \c rhs diff --git a/base_c/src/duration.c b/base_c/src/duration.c index 565b6f3..a8d376d 100644 --- a/base_c/src/duration.c +++ b/base_c/src/duration.c @@ -183,7 +183,6 @@ int embb_duration_as_seconds(const embb_duration_t* duration, if (duration->nanoseconds % 1000000000 > 0) { return EMBB_UNDERFLOW; } - assert(duration->nanoseconds % 1000000000 == 0); if (duration->seconds > ULLONG_MAX) { return EMBB_OVERFLOW; } @@ -193,12 +192,8 @@ int embb_duration_as_seconds(const embb_duration_t* duration, int embb_duration_compare(const embb_duration_t* lhs, const embb_duration_t* rhs) { - if (lhs == NULL || rhs == NULL) { - return EMBB_ERROR; - } - if (lhs->nanoseconds >= 1000000000 || rhs->nanoseconds >= 1000000000) { - return EMBB_ERROR; - } + assert(lhs != NULL && rhs != NULL); + assert(lhs->nanoseconds < 1000000000 && rhs->nanoseconds < 1000000000); if (lhs->seconds > rhs->seconds) { return 1; } else if (lhs->seconds < rhs->seconds) { diff --git a/base_c/src/log.c b/base_c/src/log.c index a622275..bf733e9 100644 --- a/base_c/src/log.c +++ b/base_c/src/log.c @@ -27,6 +27,7 @@ #include #include #include +#include #include @@ -35,6 +36,7 @@ void embb_log_write_file( void * context, char const * message) { + assert(context != NULL); FILE * ff = (FILE*)context; fprintf(ff, "%s", message); fflush(ff); diff --git a/base_c/src/time.c b/base_c/src/time.c index 045fa13..0b0d3fe 100644 --- a/base_c/src/time.c +++ b/base_c/src/time.c @@ -33,13 +33,8 @@ void embb_time_now(embb_time_t* time) { } int embb_time_compare(const embb_time_t* lhs, const embb_time_t* rhs) { - if (lhs == NULL || rhs == NULL) { - return EMBB_ERROR; - } - if (lhs->nanoseconds >= 1000000000 || rhs->nanoseconds >= 1000000000) { - return EMBB_ERROR; - } - + assert(lhs != NULL && rhs != NULL); + assert(lhs->nanoseconds < 1000000000 && rhs->nanoseconds < 1000000000); if (lhs->seconds > rhs->seconds) { return 1; } else if (lhs->seconds < rhs->seconds) { -- libgit2 0.26.0