]> git.ipfire.org Git - location/libloc.git/commitdiff
Fix all sorts of string formatting issues
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 6 Mar 2025 17:43:17 +0000 (17:43 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 6 Mar 2025 17:43:17 +0000 (17:43 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/database.c
src/network-list.c
src/network.c
src/resolv.c
src/stringpool.c
src/test-address.c
src/test-as.c
src/test-stringpool.c
src/writer.c

index 8bbbe79459c70cac1693a8154706613b5089d79e..8c84f0326a7347d14377d49d8c637b64e0cc8ad3 100644 (file)
@@ -156,8 +156,8 @@ static inline int __loc_database_check_boundaries(struct loc_database* db,
                return 1;
 
        DEBUG(db->ctx, "Database read check failed at %p for %zu byte(s)\n", p, length);
-       DEBUG(db->ctx, "  p      = %p (offset = %jd, length = %zu)\n", p, offset, length);
-       DEBUG(db->ctx, "  data   = %p (length = %zu)\n", db->data, db->length);
+       DEBUG(db->ctx, "  p      = %p (offset = %lu, 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);
 
@@ -258,7 +258,7 @@ static int loc_database_mmap(struct loc_database* db) {
                return 1;
        }
 
-       DEBUG(db->ctx, "Mapped database of %zu byte(s) at %p\n", db->length, db->data);
+       DEBUG(db->ctx, "Mapped database of %zd byte(s) at %p\n", db->length, db->data);
 
        // Tell the system that we expect to read data randomly
        r = madvise(db->data, db->length, MADV_RANDOM);
@@ -618,7 +618,7 @@ LOC_EXPORT int loc_database_verify(struct loc_database* db, FILE* f) {
                        break;
 
                default:
-                       ERROR(db->ctx, "Cannot compute hash for database with format %d\n",
+                       ERROR(db->ctx, "Cannot compute hash for database with format %u\n",
                                db->version);
                        r = -EINVAL;
                        goto CLEANUP;
@@ -1236,7 +1236,7 @@ LOC_EXPORT int loc_database_enumerator_next_as(
 
                r = loc_as_match_string(*as, enumerator->string);
                if (r == 1) {
-                       DEBUG(enumerator->ctx, "AS%d (%s) matches %s\n",
+                       DEBUG(enumerator->ctx, "AS%u (%s) matches %s\n",
                                loc_as_get_number(*as), loc_as_get_name(*as), enumerator->string);
 
                        return 0;
@@ -1347,12 +1347,12 @@ static int __loc_database_enumerator_next_network(
                *network = NULL;
        }
 
-       DEBUG(enumerator->ctx, "Called with a stack of %u nodes\n",
+       DEBUG(enumerator->ctx, "Called with a stack of %d nodes\n",
                enumerator->network_stack_depth);
 
        // Perform DFS
        while (enumerator->network_stack_depth > 0) {
-               DEBUG(enumerator->ctx, "Stack depth: %u\n", enumerator->network_stack_depth);
+               DEBUG(enumerator->ctx, "Stack depth: %d\n", enumerator->network_stack_depth);
 
                // Get object from top of the stack
                struct loc_node_stack* node = &enumerator->network_stack[enumerator->network_stack_depth];
index d35bf5607cfd7aae12b042af13d1bdc3083a4bed..a8fcf0e8dd2319e307d0ad4c9f26e8e08d9ac502 100644 (file)
@@ -118,7 +118,7 @@ LOC_EXPORT void loc_network_list_dump(struct loc_network_list* list) {
        for (unsigned int i = 0; i < list->size; i++) {
                network = list->elements[i];
 
-               INFO(list->ctx, "%4d: %s\n",
+               INFO(list->ctx, "%4u: %s\n",
                        i, loc_network_str(network));
        }
 }
index 69306a91f4b18ed0be8f4280373b34bbb7496c81..cc783234bb2db1b3b2693177887ee16c51a6030a 100644 (file)
@@ -341,7 +341,7 @@ LOC_EXPORT int loc_network_subnets(struct loc_network* network,
 
        // Check if the new prefix is valid
        if (!loc_address_valid_prefix(&network->first_address, prefix)) {
-               ERROR(network->ctx, "Invalid prefix: %d\n", prefix);
+               ERROR(network->ctx, "Invalid prefix: %u\n", prefix);
                errno = EINVAL;
                return 1;
        }
@@ -612,8 +612,8 @@ int loc_network_merge(struct loc_network** n,
 
        // We cannot shorten this any more
        if (bitlength >= prefix) {
-               DEBUG(n1->ctx, "Cannot shorten this any further because we need at least %jd bits,"
-                       " but only have %d\n", bitlength, prefix);
+               DEBUG(n1->ctx, "Cannot shorten this any further because we need at least %lu bits,"
+                       " but only have %u\n", bitlength, prefix);
 
                return 0;
        }
@@ -686,7 +686,7 @@ int loc_network_new_from_database_v1(struct loc_ctx* ctx, struct loc_network** n
        uint32_t asn = be32toh(dbobj->asn);
        r = loc_network_set_asn(*network, asn);
        if (r) {
-               ERROR(ctx, "Could not set ASN: %d\n", asn);
+               ERROR(ctx, "Could not set ASN: %u\n", asn);
                return r;
        }
 
@@ -722,7 +722,8 @@ static char* loc_network_reverse_pointer6(struct loc_network* network, const cha
                goto ERROR;
 
        for (unsigned int i = 0; i < (prefix / 4); i++) {
-               r = asprintf(&buffer, "%x.%s", loc_address_get_nibble(&network->first_address, i), buffer);
+               r = asprintf(&buffer, "%x.%s",
+                       (unsigned int)loc_address_get_nibble(&network->first_address, i), buffer);
                if (r < 0)
                        goto ERROR;
        }
index 1c4cd75a1cb069cb3e63fe73ac763caaed6cf341..64271c4ec3613195e1795c48289a44d3d386eed1 100644 (file)
@@ -133,7 +133,7 @@ LOC_EXPORT int loc_discover_latest_version(struct loc_ctx* ctx,
     }
 
     if (!size || (len = *payload) >= size || !len) {
-        ERROR(ctx, "Broken TXT record (len = %d, size = %d)\n", len, size);
+        ERROR(ctx, "Broken TXT record (len = %d, size = %u)\n", len, size);
         return -1;
     }
 
index 9986a619485f83f10961cde304c21b4a6e6e3412..2a1d5a30a1cec189aef270450e2b9ce145a16cb0 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 %zu byte(s)\n", size);
+       DEBUG(pool->ctx, "Growing string pool by %lu 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 (%zu bytes)\n", p->data, p->length);
+       DEBUG(p->ctx, "Opened string pool at %p (%jd bytes)\n", p->data, p->length);
 
        *pool = p;
        return 0;
index 7012e415546953d6dc70702f2c4a6c8322d7d054..a13af77ebcf16107c082758403c06100fdd30ad3 100644 (file)
@@ -54,7 +54,7 @@ static int perform_tests(struct loc_ctx* ctx, const int family) {
        for (unsigned int i = 0; i < 100; i++) {
                s = loc_address_str(&address);
 
-               printf("Iteration %d: %s\n", i, s);
+               printf("Iteration %u: %s\n", i, s);
 
                if (strcmp(s, e) != 0) {
                        fprintf(stderr, "IP address was formatted in an invalid format: %s\n", s);
index b135c6b9ffd91d1369b1da94c99123c25a85ce0a..07861d45e14492a98b4396b9283495b5469afbbb 100644 (file)
@@ -85,7 +85,7 @@ int main(int argc, char** argv) {
        for (unsigned int i = 1; i <= 10; i++) {
                err = loc_database_get_as(db, &as, i);
                if (err) {
-                       fprintf(stderr, "Could not find AS%d\n", i);
+                       fprintf(stderr, "Could not find AS%u\n", i);
                        exit(EXIT_FAILURE);
                }
 
@@ -110,7 +110,7 @@ int main(int argc, char** argv) {
        }
 
        while (as) {
-               printf("Found AS%d: %s\n", loc_as_get_number(as), loc_as_get_name(as));
+               printf("Found AS%u: %s\n", loc_as_get_number(as), loc_as_get_name(as));
 
                err = loc_database_enumerator_next_as(enumerator, &as);
                if (err) {
index a94d8f8bd07815e65f6024ee6f5dc4f3d0c4c54b..5439e5691c0810ef9286a2e1f82d304e35732f2a 100644 (file)
@@ -108,7 +108,7 @@ int main(int argc, char** argv) {
                free(string);
 
                if (pos < 0) {
-                       fprintf(stderr, "Could not add string %d: %m\n", i);
+                       fprintf(stderr, "Could not add string %u: %m\n", i);
                        exit(EXIT_FAILURE);
                }
        }
index ec5f89618c9900dc982a296ebd854aa475779d0d..9c1db3acb305cb84536bd9f0c8aba5e752987d58 100644 (file)
@@ -479,7 +479,7 @@ static int loc_database_write_networks(struct loc_writer* writer,
                }
 
                // Write the current node
-               DEBUG(writer->ctx, "Writing node %p (0 = %d, 1 = %d)\n",
+               DEBUG(writer->ctx, "Writing node %p (0 = %u, 1 = %u)\n",
                        node, node->index_zero, node->index_one);
 
                *offset += fwrite(&db_node, 1, sizeof(db_node), f);
@@ -655,11 +655,11 @@ LOC_EXPORT int loc_writer_write(struct loc_writer* writer, FILE* f, enum loc_dat
                        break;
 
                default:
-                       ERROR(writer->ctx, "Invalid database version: %d\n", version);
+                       ERROR(writer->ctx, "Invalid database version: %u\n", version);
                        return -1;
        }
 
-       DEBUG(writer->ctx, "Writing database in version %d\n", version);
+       DEBUG(writer->ctx, "Writing database in version %u\n", version);
 
        struct loc_database_magic magic;
        make_magic(writer, &magic, version);