From d1c5e1c19309e8351b582d039ebb3ab2fe3b8b66 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Mon, 10 Mar 2025 10:43:59 +0000 Subject: [PATCH] Fix string formatting issues on 32 bit systems Signed-off-by: Michael Tremer --- src/database.c | 10 +++++----- src/network.c | 6 +++--- src/stringpool.c | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/database.c b/src/database.c index 8c84f03..a54d72a 100644 --- a/src/database.c +++ b/src/database.c @@ -79,7 +79,7 @@ struct loc_database { // Data mapped into memory char* data; - off_t length; + ssize_t length; struct loc_stringpool* pool; @@ -149,17 +149,17 @@ struct loc_database_enumerator { static inline int __loc_database_check_boundaries(struct loc_database* db, const char* p, const size_t length) { - size_t offset = p - db->data; + ssize_t offset = p - db->data; // Return if everything is within the boundary - if (offset <= db->length - length) + if (offset <= (ssize_t)(db->length - length)) return 1; DEBUG(db->ctx, "Database read check failed at %p for %zu byte(s)\n", p, length); - DEBUG(db->ctx, " p = %p (offset = %lu, length = %zu)\n", p, offset, length); + DEBUG(db->ctx, " p = %p (offset = %zd, length = %zu)\n", p, offset, length); DEBUG(db->ctx, " data = %p (length = %zd)\n", db->data, db->length); DEBUG(db->ctx, " end = %p\n", db->data + db->length); - DEBUG(db->ctx, " overflow of %zu byte(s)\n", offset + length - db->length); + DEBUG(db->ctx, " overflow of %zd byte(s)\n", (ssize_t)(offset + length - db->length)); // Otherwise raise EFAULT errno = EFAULT; diff --git a/src/network.c b/src/network.c index cc78323..03e26d0 100644 --- a/src/network.c +++ b/src/network.c @@ -605,15 +605,15 @@ int loc_network_merge(struct loc_network** n, if (!n1->prefix || !n2->prefix) return 0; - const unsigned int prefix = loc_network_prefix(n1); + const size_t prefix = loc_network_prefix(n1); // How many bits do we need to represent this address? const size_t bitlength = loc_address_bit_length(&n1->first_address); // We cannot shorten this any more if (bitlength >= prefix) { - DEBUG(n1->ctx, "Cannot shorten this any further because we need at least %lu bits," - " but only have %u\n", bitlength, prefix); + DEBUG(n1->ctx, "Cannot shorten this any further because we need at least %zu bits," + " but only have %zu\n", bitlength, prefix); return 0; } diff --git a/src/stringpool.c b/src/stringpool.c index 2a1d5a3..f2f55e0 100644 --- a/src/stringpool.c +++ b/src/stringpool.c @@ -43,7 +43,7 @@ struct loc_stringpool { }; static int loc_stringpool_grow(struct loc_stringpool* pool, const size_t size) { - DEBUG(pool->ctx, "Growing string pool by %lu byte(s)\n", size); + DEBUG(pool->ctx, "Growing string pool by %zu byte(s)\n", size); // Increment size pool->size += size; @@ -127,7 +127,7 @@ int loc_stringpool_open(struct loc_ctx* ctx, struct loc_stringpool** pool, p->data = data; p->length = length; - DEBUG(p->ctx, "Opened string pool at %p (%jd bytes)\n", p->data, p->length); + DEBUG(p->ctx, "Opened string pool at %p (%zd bytes)\n", p->data, p->length); *pool = p; return 0; -- 2.47.2