summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2014-05-13 03:15:41 +0200
committerJeremy Allison <jra@samba.org>2014-05-22 21:05:15 +0200
commitc0b0648555cd6193a587da4810ac2b0543497ea8 (patch)
tree515a34e4db98ab52266a2baeb6f3e8fc5a0ff6f3 /lib
parent549338ff38e8689666890348d678bec7e1b0fe5e (diff)
downloadsamba-c0b0648555cd6193a587da4810ac2b0543497ea8.tar.gz
samba-c0b0648555cd6193a587da4810ac2b0543497ea8.tar.xz
samba-c0b0648555cd6193a587da4810ac2b0543497ea8.zip
tdb: use asprintf() to simplify tdb_summary()
Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Michael Adam <obnox@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/tdb/common/summary.c13
1 files changed, 6 insertions, 7 deletions
diff --git a/lib/tdb/common/summary.c b/lib/tdb/common/summary.c
index a22c17d50d8..22404afa9b8 100644
--- a/lib/tdb/common/summary.c
+++ b/lib/tdb/common/summary.c
@@ -92,7 +92,8 @@ _PUBLIC_ char *tdb_summary(struct tdb_context *tdb)
struct tdb_record rec;
char *ret = NULL;
bool locked;
- size_t len, unc = 0;
+ size_t unc = 0;
+ int len;
struct tdb_record recovery;
/* Read-only databases use no locking at all: it's best-effort.
@@ -163,13 +164,8 @@ _PUBLIC_ char *tdb_summary(struct tdb_context *tdb)
for (off = 0; off < tdb->hash_size; off++)
tally_add(&hashval, get_hash_length(tdb, off));
- /* 20 is max length of a %zu. */
- len = strlen(SUMMARY_FORMAT) + 35*20 + 1;
- ret = (char *)malloc(len);
- if (!ret)
- goto unlock;
- snprintf(ret, len, SUMMARY_FORMAT,
+ len = asprintf(&ret, SUMMARY_FORMAT,
tdb->map_size, keys.total+data.total,
keys.num,
(tdb->hash_fn == tdb_jenkins_hash)?"yes":"no",
@@ -194,6 +190,9 @@ _PUBLIC_ char *tdb_summary(struct tdb_context *tdb)
* 100.0 / tdb->map_size,
tdb->hash_size * sizeof(tdb_off_t)
* 100.0 / tdb->map_size);
+ if (len == -1) {
+ goto unlock;
+ }
unlock:
if (locked) {