From 6b59f1442af9bf3160bee6aab79b9d407f704a6f Mon Sep 17 00:00:00 2001 From: kanoi Date: Fri, 30 Sep 2016 06:20:08 +1000 Subject: [PATCH] ckdb - log errors for calls to _data_to_buf with null data --- src/ckdb.h | 2 +- src/ckdb_data.c | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/ckdb.h b/src/ckdb.h index fcfa21d5..ff6ca9d9 100644 --- a/src/ckdb.h +++ b/src/ckdb.h @@ -58,7 +58,7 @@ #define DB_VLOCK "1" #define DB_VERSION "1.0.7" -#define CKDB_VERSION DB_VERSION"-2.515" +#define CKDB_VERSION DB_VERSION"-2.516" #define WHERE_FFL " - from %s %s() line %d" #define WHERE_FFL_HERE __FILE__, __func__, __LINE__ diff --git a/src/ckdb_data.c b/src/ckdb_data.c index 38bd969b..74d30032 100644 --- a/src/ckdb_data.c +++ b/src/ckdb_data.c @@ -505,9 +505,27 @@ void _txt_to_double(char *nam, char *fld, double *data, size_t siz, WHERE_FFL_AR char *_data_to_buf(enum data_type typ, void *data, char *buf, size_t siz, WHERE_FFL_ARGS) { + static bool had_null = false; struct tm tm; double d; + // Return an empty string but only log a console message the first time + if (!data) { + // locking doesn't matter - if we get extra messages + if (!had_null) { + had_null = true; + LOGEMERG("%s() BUG - called with null data - check" + " log file" WHERE_FFL, + __func__, WHERE_FFL_PASS); + } + LOGNOTICE("%s() BUG - called with null data typ=%d" WHERE_FFL, + __func__, (int)typ, WHERE_FFL_PASS); + if (!buf) + buf = malloc(1); + *buf = '\0'; + return buf; + } + if (!buf) { switch (typ) { case TYPE_STR: