Skip to content

Commit b3e3387

Browse files
committed
printf portability: replace %zu with PRIuMAX in tests and context diagnostics; tidy/format clean
1 parent 97bd89b commit b3e3387

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

libgitledger/core/context.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "gitledger/context.h"
22

3+
#include <inttypes.h>
34
#include <stdatomic.h>
45
#include <stdbool.h>
56
#include <stdint.h>
@@ -138,9 +139,10 @@ static void context_debug_log_live_errors(size_t live_count)
138139
}
139140
char buf[GITLEDGER_CONTEXT_DIAG_BUF];
140141
size_t length = 0U;
141-
int written_chars = snprintf(
142-
buf, sizeof buf,
143-
"gitledger_context_destroy: %zu live error(s) at context teardown (leaked)\n", live_count);
142+
int written_chars = snprintf(buf, sizeof buf,
143+
"gitledger_context_destroy: %" PRIuMAX
144+
" live error(s) at context teardown (leaked)\n",
145+
(uintmax_t) live_count);
144146
if (written_chars < 0)
145147
{
146148
const char* fallback =
@@ -177,10 +179,10 @@ static void context_register_error(gitledger_context_t* ctx, gitledger_error_t*
177179
if (!node)
178180
{
179181
/* Tracking failed — live errors may not be observed at teardown. */
180-
fprintf(stderr,
181-
"GITLEDGER: context_register_error: alloc failed (ctx=%p, err=%p) — "
182-
"lifecycle guard may be impaired\n",
183-
(void*) ctx, (void*) err);
182+
(void) fprintf(stderr,
183+
"GITLEDGER: context_register_error: alloc failed (ctx=%p, err=%p) — "
184+
"lifecycle guard may be impaired\n",
185+
(void*) ctx, (void*) err);
184186
return;
185187
}
186188
node->error = err;

tests/version_test.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "gitledger/version.h"
22

3+
#include <inttypes.h>
34
#include <stddef.h>
45
#include <stdio.h>
56
#include <string.h>
@@ -14,8 +15,9 @@ int main(void)
1415

1516
if (written != expected_len)
1617
{
17-
fprintf(stderr, "version_test: expected snprintf length %zu, got %zu\n", expected_len,
18-
written);
18+
fprintf(stderr,
19+
"version_test: expected snprintf length %" PRIuMAX ", got %" PRIuMAX "\n",
20+
(uintmax_t) expected_len, (uintmax_t) written);
1921
fprintf(stderr, "version_test: buffer contents >>%s<<\n", buffer);
2022
return 1;
2123
}
@@ -54,7 +56,8 @@ int main(void)
5456
size_t ret = gitledger_semantic_version_snprintf(tiny, 0);
5557
if (ret != expected_len)
5658
{
57-
fprintf(stderr, "version_test: n=0 expected %zu, got %zu\n", expected_len, ret);
59+
fprintf(stderr, "version_test: n=0 expected %" PRIuMAX ", got %" PRIuMAX "\n",
60+
(uintmax_t) expected_len, (uintmax_t) ret);
5861
return 1;
5962
}
6063
if (tiny[0] != 'X')
@@ -71,7 +74,8 @@ int main(void)
7174
size_t ret = gitledger_semantic_version_snprintf(small, sizeof small);
7275
if (ret != expected_len)
7376
{
74-
fprintf(stderr, "version_test: n=5 expected %zu, got %zu\n", expected_len, ret);
77+
fprintf(stderr, "version_test: n=5 expected %" PRIuMAX ", got %" PRIuMAX "\n",
78+
(uintmax_t) expected_len, (uintmax_t) ret);
7579
return 1;
7680
}
7781
if (small[sizeof small - 1] != '\0')

0 commit comments

Comments
 (0)