From: Sebastian Harl Date: Sat, 7 Mar 2015 12:56:32 +0000 (+0100) Subject: data: Let strlen/format handle NULL values correctly. X-Git-Tag: sysdb-0.8.0~137 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=7ee46a4a7e492518a56df4a8ae3f1bd88adf88b8;p=sysdb.git data: Let strlen/format handle NULL values correctly. --- diff --git a/src/core/data.c b/src/core/data.c index d34a4dd..9f2b506 100644 --- a/src/core/data.c +++ b/src/core/data.c @@ -871,7 +871,11 @@ sdb_data_strlen(const sdb_data_t *datum) if (! datum) return 0; - if (datum->type == SDB_TYPE_INTEGER) { + if (sdb_data_isnull(datum)) { + /* NULL */ + return 4; + } + else if (datum->type == SDB_TYPE_INTEGER) { /* log(64) */ return 20; } @@ -927,7 +931,11 @@ sdb_data_format(const sdb_data_t *datum, char *buf, size_t buflen, int quoted) if ((! datum) || (! buf) || (! buflen)) return -1; - if (datum->type == SDB_TYPE_INTEGER) { + if (datum->type == SDB_TYPE_NULL) { + strncpy(buf, "NULL", buflen); + ret = 4; + } + else if (datum->type == SDB_TYPE_INTEGER) { ret = snprintf(buf, buflen, "%"PRIi64, datum->data.integer); } else if (datum->type == SDB_TYPE_DECIMAL) {