From d7e60bc17e1f5428e5459e6d60a7c8b1f146a3aa Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Wed, 9 Aug 2017 09:58:35 +0200 Subject: [PATCH] tdb: Do not allow to pass NULL as the buffer to transaction_write() This fixes a GCC warning. Signed-off-by: Andreas Schneider Reviewed-by: Volker Lendecke Autobuild-User(master): Andreas Schneider Autobuild-Date(master): Thu Aug 10 02:26:09 CEST 2017 on sn-devel-144 --- lib/tdb/common/transaction.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/tdb/common/transaction.c b/lib/tdb/common/transaction.c index c570cee48da..8ec00256924 100644 --- a/lib/tdb/common/transaction.c +++ b/lib/tdb/common/transaction.c @@ -210,6 +210,10 @@ static int transaction_write(struct tdb_context *tdb, tdb_off_t off, { uint32_t blk; + if (buf == NULL) { + return -1; + } + /* Only a commit is allowed on a prepared transaction */ if (tdb->transaction->prepared) { tdb->ecode = TDB_ERR_EINVAL; @@ -234,9 +238,7 @@ static int transaction_write(struct tdb_context *tdb, tdb_off_t off, } len -= len2; off += len2; - if (buf != NULL) { - buf = (const void *)(len2 + (const char *)buf); - } + buf = (const void *)(len2 + (const char *)buf); } if (len == 0) { @@ -289,11 +291,7 @@ static int transaction_write(struct tdb_context *tdb, tdb_off_t off, } /* overwrite part of an existing block */ - if (buf == NULL) { - memset(tdb->transaction->blocks[blk] + off, 0, len); - } else { - memcpy(tdb->transaction->blocks[blk] + off, buf, len); - } + memcpy(tdb->transaction->blocks[blk] + off, buf, len); if (blk == tdb->transaction->num_blocks-1) { if (len + off > tdb->transaction->last_block_size) { tdb->transaction->last_block_size = len + off; -- 2.11.4.GIT