From: Michael Tremer Date: Thu, 6 Mar 2025 17:43:17 +0000 (+0000) Subject: Fix all sorts of string formatting issues X-Git-Tag: 0.9.18~19 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=64c01ef0b0235277a197f069df9947facde0f7df;p=location%2Flibloc.git Fix all sorts of string formatting issues Signed-off-by: Michael Tremer --- diff --git a/src/database.c b/src/database.c index 8bbbe79..8c84f03 100644 --- a/src/database.c +++ b/src/database.c @@ -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]; diff --git a/src/network-list.c b/src/network-list.c index d35bf56..a8fcf0e 100644 --- a/src/network-list.c +++ b/src/network-list.c @@ -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)); } } diff --git a/src/network.c b/src/network.c index 69306a9..cc78323 100644 --- a/src/network.c +++ b/src/network.c @@ -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; } diff --git a/src/resolv.c b/src/resolv.c index 1c4cd75..64271c4 100644 --- a/src/resolv.c +++ b/src/resolv.c @@ -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; } diff --git a/src/stringpool.c b/src/stringpool.c index 9986a61..2a1d5a3 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 %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; diff --git a/src/test-address.c b/src/test-address.c index 7012e41..a13af77 100644 --- a/src/test-address.c +++ b/src/test-address.c @@ -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); diff --git a/src/test-as.c b/src/test-as.c index b135c6b..07861d4 100644 --- a/src/test-as.c +++ b/src/test-as.c @@ -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) { diff --git a/src/test-stringpool.c b/src/test-stringpool.c index a94d8f8..5439e56 100644 --- a/src/test-stringpool.c +++ b/src/test-stringpool.c @@ -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); } } diff --git a/src/writer.c b/src/writer.c index ec5f896..9c1db3a 100644 --- a/src/writer.c +++ b/src/writer.c @@ -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);