]> git.ipfire.org Git - location/libloc.git/commitdiff
Fix string formatting issues on 32 bit systems
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 10 Mar 2025 10:43:59 +0000 (10:43 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 10 Mar 2025 10:43:59 +0000 (10:43 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/database.c
src/network.c
src/stringpool.c

index 8c84f0326a7347d14377d49d8c637b64e0cc8ad3..a54d72abe0a8b407ee3721e528e154d8eeb51966 100644 (file)
@@ -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;
index cc783234bb2db1b3b2693177887ee16c51a6030a..03e26d0d7ef80a62b5f347033e31a64e97ac0e84 100644 (file)
@@ -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;
        }
index 2a1d5a30a1cec189aef270450e2b9ce145a16cb0..f2f55e079ba38f5bbe729bfeb514b7be0005ac3e 100644 (file)
@@ -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;