]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
tdb: fix compilation with TDB_TRACE=1
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Wed, 10 Jul 2024 02:35:28 +0000 (14:35 +1200)
committerDouglas Bagnall <dbagnall@samba.org>
Sat, 27 Jul 2024 22:47:39 +0000 (22:47 +0000)
../../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 <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
lib/tdb/common/tdb.c

index de829bb48c4e4f391d49581962b6be53129933b9..4ad01b2b360b2b5027b38a68d76a852cbc627433 100644 (file)
@@ -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);
 }