From: Douglas Bagnall Date: Wed, 10 Jul 2024 02:35:28 +0000 (+1200) Subject: tdb: fix compilation with TDB_TRACE=1 X-Git-Tag: tdb-1.4.11~9 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e653b0870fd5d5684d90497565efc8463a72192a;p=thirdparty%2Fsamba.git tdb: fix compilation with TDB_TRACE=1 ../../lib/tdb/common/tdb.c: In function ‘tdb_trace_record’: ../../lib/tdb/common/tdb.c:1224:22: error: ‘snprintf’ output truncated before the last format character [-Werror=format-truncation=] 1224 | p += snprintf(p, 2, %02x, rec.dptr[i]); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../../lib/tdb/common/tdb.c:1224:22: note: ‘snprintf’ output 3 bytes into a destination of size 2 cc1: all warnings being treated as errors Signed-off-by: Douglas Bagnall Reviewed-by: Stefan Metzmacher --- diff --git a/lib/tdb/common/tdb.c b/lib/tdb/common/tdb.c index de829bb48c4..4ad01b2b360 100644 --- a/lib/tdb/common/tdb.c +++ b/lib/tdb/common/tdb.c @@ -1208,7 +1208,7 @@ static void tdb_trace_end_ret(struct tdb_context *tdb, int ret) static void tdb_trace_record(struct tdb_context *tdb, TDB_DATA rec) { - char msg[20 + rec.dsize*2], *p; + char msg[21 + rec.dsize*2], *p; unsigned int i; /* We differentiate zero-length records from non-existent ones. */ @@ -1220,8 +1220,11 @@ static void tdb_trace_record(struct tdb_context *tdb, TDB_DATA rec) /* snprintf here is purely cargo-cult programming. */ p = msg; p += snprintf(p, sizeof(msg), " %zu:", rec.dsize); - for (i = 0; i < rec.dsize; i++) - p += snprintf(p, 2, "%02x", rec.dptr[i]); + + for (i = 0; i < rec.dsize; i++) { + snprintf(p, 3, "%02x", rec.dptr[i]); + p += 2; + } tdb_trace_write(tdb, msg); }