From d26a66875ac769a5e8756c101bd4e47a40d8fafa Mon Sep 17 00:00:00 2001 From: Alex 'AdUser' Z Date: Thu, 15 Feb 2018 22:50:35 +1000 Subject: [PATCH] * simdb-tool : better error handling of simdb_usage_*() --- src/simdb-tool.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/simdb-tool.c b/src/simdb-tool.c index e905f9a..8c204bf 100644 --- a/src/simdb-tool.c +++ b/src/simdb-tool.c @@ -123,8 +123,8 @@ int db_usage_map(simdb_t *db, int cols) { int records, pos; uint8_t rest = 0; - if ((records = simdb_usage_map(db, &map)) == 0) { - fprintf(stderr, "database usage: can't get database map\n"); + if ((records = simdb_usage_map(db, &map)) <= 0) { + fprintf(stderr, "database usage: can't get database map -- %s\n", simdb_error(records)); FREE(map); return 1; } @@ -156,7 +156,10 @@ int db_usage_map(simdb_t *db, int cols) { int db_usage_slice(simdb_t *db, int offset, uint16_t limit) { char *map = NULL; - limit = simdb_usage_slice(db, &map, offset, limit); + if ((limit = simdb_usage_slice(db, &map, offset, limit)) <= 0) { + fprintf(stderr, "database usage: can't get database slice -- %s\n", simdb_error(limit)); + return 1; + } for (uint16_t i = 0; i < limit; i++) map[i] = map[i] ? CHAR_USED : CHAR_FREE; puts(map);