From 3bd686c5ad4756af1033ac14ba09a40156cc6d47 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Tue, 28 May 2013 16:53:56 +0930 Subject: tdb: fix logging of offets and lengths. We can have offsets > 2G, so use unsigned values. Fixes other prints to be native types rather than casts, too. Signed-off-by: Rusty Russell Reviewed-by: Andrew Bartlett Autobuild-User(master): Andrew Bartlett Autobuild-Date(master): Tue May 28 11:22:14 CEST 2013 on sn-devel-104 --- lib/tdb/common/check.c | 22 +++++++++++----------- lib/tdb/common/dump.c | 9 ++++----- lib/tdb/common/freelist.c | 8 ++++---- lib/tdb/common/io.c | 36 ++++++++++++++++++------------------ lib/tdb/common/lock.c | 8 ++++---- lib/tdb/common/summary.c | 2 +- lib/tdb/common/transaction.c | 8 ++++---- 7 files changed, 46 insertions(+), 47 deletions(-) (limited to 'lib') diff --git a/lib/tdb/common/check.c b/lib/tdb/common/check.c index dc38102f0c..9f9d8708c1 100644 --- a/lib/tdb/common/check.c +++ b/lib/tdb/common/check.c @@ -76,19 +76,19 @@ static bool tdb_check_record(struct tdb_context *tdb, /* Check rec->next: 0 or points to record offset, aligned. */ if (rec->next > 0 && rec->next < TDB_DATA_START(tdb->hash_size)){ TDB_LOG((tdb, TDB_DEBUG_ERROR, - "Record offset %d too small next %d\n", + "Record offset %u too small next %u\n", off, rec->next)); goto corrupt; } if (rec->next + sizeof(*rec) < rec->next) { TDB_LOG((tdb, TDB_DEBUG_ERROR, - "Record offset %d too large next %d\n", + "Record offset %u too large next %u\n", off, rec->next)); goto corrupt; } if ((rec->next % TDB_ALIGNMENT) != 0) { TDB_LOG((tdb, TDB_DEBUG_ERROR, - "Record offset %d misaligned next %d\n", + "Record offset %u misaligned next %u\n", off, rec->next)); goto corrupt; } @@ -98,14 +98,14 @@ static bool tdb_check_record(struct tdb_context *tdb, /* Check rec_len: similar to rec->next, implies next record. */ if ((rec->rec_len % TDB_ALIGNMENT) != 0) { TDB_LOG((tdb, TDB_DEBUG_ERROR, - "Record offset %d misaligned length %d\n", + "Record offset %u misaligned length %u\n", off, rec->rec_len)); goto corrupt; } /* Must fit tailer. */ if (rec->rec_len < sizeof(tailer)) { TDB_LOG((tdb, TDB_DEBUG_ERROR, - "Record offset %d too short length %d\n", + "Record offset %u too short length %u\n", off, rec->rec_len)); goto corrupt; } @@ -119,7 +119,7 @@ static bool tdb_check_record(struct tdb_context *tdb, goto corrupt; if (tailer != sizeof(*rec) + rec->rec_len) { TDB_LOG((tdb, TDB_DEBUG_ERROR, - "Record offset %d invalid tailer\n", off)); + "Record offset %u invalid tailer\n", off)); goto corrupt; } @@ -247,7 +247,7 @@ static bool tdb_check_used_record(struct tdb_context *tdb, /* key + data + tailer must fit in record */ if (rec->key_len + rec->data_len + sizeof(tdb_off_t) > rec->rec_len) { TDB_LOG((tdb, TDB_DEBUG_ERROR, - "Record offset %d too short for contents\n", off)); + "Record offset %u too short for contents\n", off)); return false; } @@ -257,7 +257,7 @@ static bool tdb_check_used_record(struct tdb_context *tdb, if (tdb->hash_fn(&key) != rec->full_hash) { TDB_LOG((tdb, TDB_DEBUG_ERROR, - "Record offset %d has incorrect hash\n", off)); + "Record offset %u has incorrect hash\n", off)); goto fail_put_key; } @@ -411,14 +411,14 @@ _PUBLIC_ int tdb_check(struct tdb_context *tdb, goto corrupt; TDB_LOG((tdb, TDB_DEBUG_ERROR, - "Dead space at %d-%d (of %u)\n", + "Dead space at %u-%u (of %u)\n", off, off + dead, tdb->map_size)); rec.rec_len = dead - sizeof(rec); break; case TDB_RECOVERY_MAGIC: if (recovery_start != off) { TDB_LOG((tdb, TDB_DEBUG_ERROR, - "Unexpected recovery record at offset %d\n", + "Unexpected recovery record at offset %u\n", off)); goto free; } @@ -428,7 +428,7 @@ _PUBLIC_ int tdb_check(struct tdb_context *tdb, corrupt: tdb->ecode = TDB_ERR_CORRUPT; TDB_LOG((tdb, TDB_DEBUG_ERROR, - "Bad magic 0x%x at offset %d\n", + "Bad magic 0x%x at offset %u\n", rec.magic, off)); goto free; } diff --git a/lib/tdb/common/dump.c b/lib/tdb/common/dump.c index f4682fa289..7193c1e110 100644 --- a/lib/tdb/common/dump.c +++ b/lib/tdb/common/dump.c @@ -39,8 +39,8 @@ static tdb_off_t tdb_dump_record(struct tdb_context *tdb, int hash, return 0; } - printf(" rec: hash=%d offset=0x%08x next=0x%08x rec_len=%d " - "key_len=%d data_len=%d full_hash=0x%x magic=0x%x\n", + printf(" rec: hash=%d offset=0x%08x next=0x%08x rec_len=%u " + "key_len=%u data_len=%u full_hash=0x%x magic=0x%x\n", hash, offset, rec.next, rec.rec_len, rec.key_len, rec.data_len, rec.full_hash, rec.magic); @@ -122,15 +122,14 @@ _PUBLIC_ int tdb_printfreelist(struct tdb_context *tdb) return -1; } - printf("entry offset=[0x%08x], rec.rec_len = [0x%08x (%d)] (end = 0x%08x)\n", + printf("entry offset=[0x%08x], rec.rec_len = [0x%08x (%u)] (end = 0x%08x)\n", rec_ptr, rec.rec_len, rec.rec_len, rec_ptr + rec.rec_len); total_free += rec.rec_len; /* move to the next record */ rec_ptr = rec.next; } - printf("total rec_len = [0x%08x (%d)]\n", (int)total_free, - (int)total_free); + printf("total rec_len = [0x%08lx (%lu)]\n", total_free, total_free); return tdb_unlock(tdb, -1, F_WRLCK); } diff --git a/lib/tdb/common/freelist.c b/lib/tdb/common/freelist.c index 2c58c6918f..ea14dd02ab 100644 --- a/lib/tdb/common/freelist.c +++ b/lib/tdb/common/freelist.c @@ -42,7 +42,7 @@ int tdb_rec_free_read(struct tdb_context *tdb, tdb_off_t off, struct tdb_record if (rec->magic == TDB_MAGIC) { /* this happens when a app is showdown while deleting a record - we should not completely fail when this happens */ - TDB_LOG((tdb, TDB_DEBUG_WARNING, "tdb_rec_free_read non-free magic 0x%x at offset=%d - fixing\n", + TDB_LOG((tdb, TDB_DEBUG_WARNING, "tdb_rec_free_read non-free magic 0x%x at offset=%u - fixing\n", rec->magic, off)); rec->magic = TDB_FREE_MAGIC; if (tdb_rec_write(tdb, off, rec) == -1) @@ -52,7 +52,7 @@ int tdb_rec_free_read(struct tdb_context *tdb, tdb_off_t off, struct tdb_record if (rec->magic != TDB_FREE_MAGIC) { /* Ensure ecode is set for log fn. */ tdb->ecode = TDB_ERR_CORRUPT; - TDB_LOG((tdb, TDB_DEBUG_WARNING, "tdb_rec_free_read bad magic 0x%x at offset=%d\n", + TDB_LOG((tdb, TDB_DEBUG_WARNING, "tdb_rec_free_read bad magic 0x%x at offset=%u\n", rec->magic, off)); return -1; } @@ -79,7 +79,7 @@ static int remove_from_freelist(struct tdb_context *tdb, tdb_off_t off, tdb_off_ last_ptr = i; } tdb->ecode = TDB_ERR_CORRUPT; - TDB_LOG((tdb, TDB_DEBUG_FATAL,"remove_from_freelist: not on list at off=%d\n", off)); + TDB_LOG((tdb, TDB_DEBUG_FATAL,"remove_from_freelist: not on list at off=%u\n", off)); return -1; } #endif @@ -195,7 +195,7 @@ update: if (tdb_ofs_read(tdb, FREELIST_TOP, &rec->next) == -1 || tdb_rec_write(tdb, offset, rec) == -1 || tdb_ofs_write(tdb, FREELIST_TOP, &offset) == -1) { - TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_free record write failed at offset=%d\n", offset)); + TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_free record write failed at offset=%u\n", offset)); goto fail; } diff --git a/lib/tdb/common/io.c b/lib/tdb/common/io.c index 7e29c38440..a477fb55e4 100644 --- a/lib/tdb/common/io.c +++ b/lib/tdb/common/io.c @@ -40,8 +40,8 @@ static int tdb_oob(struct tdb_context *tdb, tdb_off_t off, tdb_len_t len, if (!probe) { /* Ensure ecode is set for log fn. */ tdb->ecode = TDB_ERR_IO; - TDB_LOG((tdb, TDB_DEBUG_FATAL,"tdb_oob off %d len %d wrap\n", - (int)off, (int)len)); + TDB_LOG((tdb, TDB_DEBUG_FATAL,"tdb_oob off %u len %u wrap\n", + off, len)); } return -1; } @@ -127,8 +127,8 @@ static int tdb_write(struct tdb_context *tdb, tdb_off_t off, /* try once more */ tdb->ecode = TDB_ERR_IO; TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_write: wrote only " - "%d of %d bytes at %d, trying once more\n", - (int)written, len, off)); + "%zi of %u bytes at %u, trying once more\n", + written, len, off)); written = pwrite(tdb->fd, (const char *)buf+written, len-written, off+written); @@ -136,13 +136,13 @@ static int tdb_write(struct tdb_context *tdb, tdb_off_t off, if (written == -1) { /* Ensure ecode is set for log fn. */ tdb->ecode = TDB_ERR_IO; - TDB_LOG((tdb, TDB_DEBUG_FATAL,"tdb_write failed at %d " - "len=%d (%s)\n", off, len, strerror(errno))); + TDB_LOG((tdb, TDB_DEBUG_FATAL,"tdb_write failed at %u " + "len=%u (%s)\n", off, len, strerror(errno))); return -1; } else if (written != (ssize_t)len) { tdb->ecode = TDB_ERR_IO; TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_write: failed to " - "write %d bytes at %d in two attempts\n", + "write %u bytes at %u in two attempts\n", len, off)); return -1; } @@ -180,10 +180,10 @@ static int tdb_read(struct tdb_context *tdb, tdb_off_t off, void *buf, if (ret != (ssize_t)len) { /* Ensure ecode is set for log fn. */ tdb->ecode = TDB_ERR_IO; - TDB_LOG((tdb, TDB_DEBUG_FATAL,"tdb_read failed at %d " - "len=%d ret=%d (%s) map_size=%d\n", - (int)off, (int)len, (int)ret, strerror(errno), - (int)tdb->map_size)); + TDB_LOG((tdb, TDB_DEBUG_FATAL,"tdb_read failed at %u " + "len=%u ret=%zi (%s) map_size=%u\n", + off, len, ret, strerror(errno), + tdb->map_size)); return -1; } #endif @@ -266,7 +266,7 @@ int tdb_mmap(struct tdb_context *tdb) if (tdb->map_ptr == MAP_FAILED) { tdb->map_ptr = NULL; - TDB_LOG((tdb, TDB_DEBUG_WARNING, "tdb_mmap failed for size %d (%s)\n", + TDB_LOG((tdb, TDB_DEBUG_WARNING, "tdb_mmap failed for size %u (%s)\n", tdb->map_size, strerror(errno))); #ifdef HAVE_INCOHERENT_MMAP tdb->ecode = TDB_ERR_IO; @@ -305,7 +305,7 @@ static int tdb_expand_file(struct tdb_context *tdb, tdb_off_t size, tdb_off_t ad errno = ENOSPC; } if (written != 1) { - TDB_LOG((tdb, TDB_DEBUG_FATAL, "expand_file to %d failed (%s)\n", + TDB_LOG((tdb, TDB_DEBUG_FATAL, "expand_file to %u failed (%s)\n", size+addition, strerror(errno))); return -1; } @@ -331,14 +331,14 @@ static int tdb_expand_file(struct tdb_context *tdb, tdb_off_t size, tdb_off_t ad } if (written == -1) { TDB_LOG((tdb, TDB_DEBUG_FATAL, "expand_file write of " - "%d bytes failed (%s)\n", (int)n, + "%u bytes failed (%s)\n", (int)n, strerror(errno))); return -1; } if (written != n) { TDB_LOG((tdb, TDB_DEBUG_WARNING, "expand_file: wrote " - "only %d of %d bytes - retrying\n", (int)written, - (int)n)); + "only %zu of %zi bytes - retrying\n", written, + n)); } addition -= written; size += written; @@ -454,7 +454,7 @@ unsigned char *tdb_alloc_read(struct tdb_context *tdb, tdb_off_t offset, tdb_len if (!(buf = (unsigned char *)malloc(len ? len : 1))) { /* Ensure ecode is set for log fn. */ tdb->ecode = TDB_ERR_OOM; - TDB_LOG((tdb, TDB_DEBUG_ERROR,"tdb_alloc_read malloc failed len=%d (%s)\n", + TDB_LOG((tdb, TDB_DEBUG_ERROR,"tdb_alloc_read malloc failed len=%u (%s)\n", len, strerror(errno))); return NULL; } @@ -507,7 +507,7 @@ int tdb_rec_read(struct tdb_context *tdb, tdb_off_t offset, struct tdb_record *r if (TDB_BAD_MAGIC(rec)) { /* Ensure ecode is set for log fn. */ tdb->ecode = TDB_ERR_CORRUPT; - TDB_LOG((tdb, TDB_DEBUG_FATAL,"tdb_rec_read bad magic 0x%x at offset=%d\n", rec->magic, offset)); + TDB_LOG((tdb, TDB_DEBUG_FATAL,"tdb_rec_read bad magic 0x%x at offset=%u\n", rec->magic, offset)); return -1; } return tdb->methods->tdb_oob(tdb, rec->next, sizeof(*rec), 0); diff --git a/lib/tdb/common/lock.c b/lib/tdb/common/lock.c index b59dfbc92c..4dfefd563d 100644 --- a/lib/tdb/common/lock.c +++ b/lib/tdb/common/lock.c @@ -169,8 +169,8 @@ int tdb_brlock(struct tdb_context *tdb, * EAGAIN is an expected return from non-blocking * locks. */ if (!(flags & TDB_LOCK_PROBE) && errno != EAGAIN) { - TDB_LOG((tdb, TDB_DEBUG_TRACE,"tdb_brlock failed (fd=%d) at offset %d rw_type=%d flags=%d len=%d\n", - tdb->fd, offset, rw_type, flags, (int)len)); + TDB_LOG((tdb, TDB_DEBUG_TRACE,"tdb_brlock failed (fd=%d) at offset %u rw_type=%d flags=%d len=%zu\n", + tdb->fd, offset, rw_type, flags, len)); } return -1; } @@ -191,8 +191,8 @@ int tdb_brunlock(struct tdb_context *tdb, } while (ret == -1 && errno == EINTR); if (ret == -1) { - TDB_LOG((tdb, TDB_DEBUG_TRACE,"tdb_brunlock failed (fd=%d) at offset %d rw_type=%d len=%d\n", - tdb->fd, offset, rw_type, (int)len)); + TDB_LOG((tdb, TDB_DEBUG_TRACE,"tdb_brunlock failed (fd=%d) at offset %u rw_type=%u len=%zu\n", + tdb->fd, offset, rw_type, len)); } return ret; } diff --git a/lib/tdb/common/summary.c b/lib/tdb/common/summary.c index ef2c49a2da..3c6f755727 100644 --- a/lib/tdb/common/summary.c +++ b/lib/tdb/common/summary.c @@ -152,7 +152,7 @@ _PUBLIC_ char *tdb_summary(struct tdb_context *tdb) break; default: TDB_LOG((tdb, TDB_DEBUG_ERROR, - "Unexpected record magic 0x%x at offset %d\n", + "Unexpected record magic 0x%x at offset %u\n", rec.magic, off)); goto unlock; } diff --git a/lib/tdb/common/transaction.c b/lib/tdb/common/transaction.c index a2498ec82d..81cfd16942 100644 --- a/lib/tdb/common/transaction.c +++ b/lib/tdb/common/transaction.c @@ -195,7 +195,7 @@ static int transaction_read(struct tdb_context *tdb, tdb_off_t off, void *buf, return 0; fail: - TDB_LOG((tdb, TDB_DEBUG_FATAL, "transaction_read: failed at off=%d len=%d\n", off, len)); + TDB_LOG((tdb, TDB_DEBUG_FATAL, "transaction_read: failed at off=%u len=%u\n", off, len)); tdb->ecode = TDB_ERR_IO; tdb->transaction->transaction_error = 1; return -1; @@ -303,7 +303,7 @@ static int transaction_write(struct tdb_context *tdb, tdb_off_t off, return 0; fail: - TDB_LOG((tdb, TDB_DEBUG_FATAL, "transaction_write: failed at off=%d len=%d\n", + TDB_LOG((tdb, TDB_DEBUG_FATAL, "transaction_write: failed at off=%u len=%u\n", (blk*tdb->transaction->block_size) + off, len)); tdb->transaction->transaction_error = 1; return -1; @@ -1217,7 +1217,7 @@ int tdb_transaction_recover(struct tdb_context *tdb) if (tdb->methods->tdb_write(tdb, ofs, p+8, len) == -1) { free(data); - TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_recover: failed to recover %d bytes at offset %d\n", len, ofs)); + TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_recover: failed to recover %u bytes at offset %u\n", len, ofs)); tdb->ecode = TDB_ERR_IO; return -1; } @@ -1255,7 +1255,7 @@ int tdb_transaction_recover(struct tdb_context *tdb) return -1; } - TDB_LOG((tdb, TDB_DEBUG_TRACE, "tdb_transaction_recover: recovered %d byte database\n", + TDB_LOG((tdb, TDB_DEBUG_TRACE, "tdb_transaction_recover: recovered %u byte database\n", recovery_eof)); /* all done */ -- cgit