Skip to content

Commit bf47725

Browse files
committed
meta: Fix up format string type specifiers
32-bit platforms (in this case armv6l) had trouble with my haphazard use of type specifiers. We now use %zu for size_t, and PRI* for other integer types. %zu is a POSIX C99 addition, so that should be fine, but I do recall having issues with PRI* on different platforms. I need to check that this builds on all platforms before rebasing it on master.
1 parent 840d471 commit bf47725

File tree

10 files changed

+19
-16
lines changed

10 files changed

+19
-16
lines changed

src/common/json_loader.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ static void parse_mesh(struct cr_renderer *r, const cJSON *data, int idx, int me
298298
long us = timer_get_us(timer);
299299
free(full_path);
300300
long ms = us / 1000;
301-
logr(debug, "Parsing file %-35s took %zu %s\n", file_name, ms > 0 ? ms : us, ms > 0 ? "ms" : "μs");
301+
logr(debug, "Parsing file %-35s took %li %s\n", file_name, ms > 0 ? ms : us, ms > 0 ? "ms" : "μs");
302302

303303
if (!result.meshes.count) return;
304304

src/common/loaders/formats/gltf/gltf.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ unsigned char *parse_buffer(const cJSON *data) {
6363
size_t decoded_length = 0;
6464
buffer = b64decode(base64data, encoded_length, &decoded_length);
6565
if (decoded_length != expected_bytes) {
66-
logr(warning, "Invalid buffer while parsing glTF. base64 decoded length of %lu, expected %lu\n", decoded_length, expected_bytes);
66+
logr(warning, "Invalid buffer while parsing glTF. base64 decoded length of %zu, expected %zu\n", decoded_length, expected_bytes);
6767
free(buffer);
6868
return NULL;
6969
}
@@ -76,7 +76,7 @@ unsigned char *parse_buffer(const cJSON *data) {
7676
}
7777
file_data data = file_load(uri_string);
7878
if (data.count != expected_bytes) {
79-
logr(warning, "Invalid buffer while parsing glTF. Loaded file %s length %lu, expected %lu", uri_string, data.count, expected_bytes);
79+
logr(warning, "Invalid buffer while parsing glTF. Loaded file %s length %zu, expected %zu", uri_string, data.count, expected_bytes);
8080
}
8181
return data.items;
8282
}

src/common/logging.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#pragma once
1010

11+
#include <inttypes.h>
1112
#include <c-ray/c-ray.h>
1213

1314
struct renderer;

src/common/mempool.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,6 @@ void destroyBlocks(struct block *head) {
5656
head = prev;
5757
}
5858
char *size = human_file_size(bytesfreed, NULL);
59-
logr(debug, "Destroyed %lu blocks, %s\n", numDestroyed, size);
59+
logr(debug, "Destroyed %zu blocks, %s\n", numDestroyed, size);
6060
free(size);
6161
}

src/common/networking.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ ssize_t chunkedReceive(int socket, char **data, size_t *length) {
124124
bail:
125125
ASSERT(leftToReceive == 0);
126126
size_t finalLength = strlen(recvBuf) + 1; // +1 for null byte
127-
if (finalLength < msgLen) logr(error, "Chunked transfer failed. Header size of %lu != %lu. This shouldn't happen.\n", msgLen, finalLength);
127+
if (finalLength < msgLen)
128+
logr(error, "Chunked transfer failed. Header size of %zu != %zu. This shouldn't happen.\n", msgLen, finalLength);
128129
*data = recvBuf;
129130
free(currentChunk);
130131
free(scratchBuf);

src/common/platform/thread_pool.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ static void *cr_worker(void *arg) {
9393
struct cr_thread_pool *thread_pool_create(size_t threads) {
9494
if (!threads) threads = 2;
9595
struct cr_thread_pool *pool = calloc(1, sizeof(*pool));
96-
logr(debug, "Spawning thread pool (%lut, %p)\n", threads, (void *)pool);
96+
logr(debug, "Spawning thread pool (%zut, %p)\n", threads, (void *)pool);
9797
pool->alive_threads = threads;
9898
pool->threads = calloc(pool->alive_threads, sizeof(*pool->threads));
9999

@@ -113,7 +113,7 @@ struct cr_thread_pool *thread_pool_create(size_t threads) {
113113

114114
void thread_pool_destroy(struct cr_thread_pool *pool) {
115115
if (!pool) return;
116-
logr(debug, "Closing thread pool (%lut, %p)\n", pool->alive_threads, (void *)pool);
116+
logr(debug, "Closing thread pool (%zut, %p)\n", pool->alive_threads, (void *)pool);
117117
mutex_lock(pool->mutex);
118118
// Clear work queue
119119
struct cr_task *head = pool->first;

src/driver/main.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ int main(int argc, char *argv[]) {
168168
goto done;
169169
}
170170
}
171-
logr(info, "JSON parse took %lums\n", json_ms);
171+
logr(info, "JSON parse took %zums\n", json_ms);
172172

173173
file_free(&input_bytes);
174174

@@ -280,11 +280,11 @@ int main(int argc, char *argv[]) {
280280
uint64_t samples = cr_renderer_get_num_pref(renderer, cr_renderer_samples);
281281
uint64_t bounces = cr_renderer_get_num_pref(renderer, cr_renderer_bounces);
282282

283-
logr(info, "Starting c-ray renderer for frame %zu\n", out_num);
283+
logr(info, "Starting c-ray renderer for frame %"PRIu64"\n", out_num);
284284
bool sys_thread = threads == (size_t)sys_get_cores() + 2;
285-
logr(info, "Rendering at %s%lu%s x %s%lu%s\n", KWHT, width, KNRM, KWHT, height, KNRM);
286-
logr(info, "Rendering %s%zu%s samples with %s%zu%s bounces.\n", KBLU, samples, KNRM, KGRN, bounces, KNRM);
287-
logr(info, "Rendering with %s%zu%s%s local thread%s.\n",
285+
logr(info, "Rendering at %s%"PRIu64"%s x %s%"PRIu64"%s\n", KWHT, width, KNRM, KWHT, height, KNRM);
286+
logr(info, "Rendering %s%"PRIu64"%s samples with %s%"PRIu64"%s bounces.\n", KBLU, samples, KNRM, KGRN, bounces, KNRM);
287+
logr(info, "Rendering with %s%"PRIu64"%s%s local thread%s.\n",
288288
KRED,
289289
sys_thread ? threads - 2 : threads,
290290
sys_thread ? "+2" : "",

src/lib/nodes/textures/image.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ static void dump(const void *node, char *dumpbuf, int len) {
6767
snprintf(dumpbuf, len, "imageTexture { tex: pending }");
6868
return;
6969
}
70-
snprintf(dumpbuf, len, "imageTexture { tex: { %lux%lu, %lu channels, %s, %s }, options: %s %s }",
70+
snprintf(dumpbuf, len, "imageTexture { tex: { %zux%zu, %zu channels, %s, %s }, options: %s %s }",
7171
self->tex->width,
7272
self->tex->height,
7373
self->tex->channels,

src/lib/protocol/server.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ struct render_client_arr clients_sync(const struct renderer *r) {
385385
char *serialized = serialize_renderer(r);
386386
size_t transfer_bytes = strlen(serialized);
387387
char buf[64];
388-
logr(info, "Sending %s to %lu client%s...\n", human_file_size(transfer_bytes, buf), clients.count, PLURAL(clients.count));
388+
logr(info, "Sending %s to %zu client%s...\n", human_file_size(transfer_bytes, buf), clients.count, PLURAL(clients.count));
389389

390390
struct sync_thread *params = calloc(clients.count, sizeof(*params));
391391
logr(debug, "Client list:\n");

src/lib/renderer/renderer.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ static void print_stats(const struct world *scene) {
5757
normals += mesh->vbuf.normals.count;
5858
}
5959
}
60-
logr(info, "Totals: %liV, %liN, %zuI, %liP, %zuS, %zuM\n",
60+
logr(info, "Totals: %"PRIu64"V, %"PRIu64"N, %zuI, %"PRIu64"P, %zuS, %zuM\n",
6161
vertices,
6262
normals,
6363
scene->instances.count,
@@ -241,7 +241,8 @@ void renderer_render(struct renderer *r) {
241241

242242
r->state.s = r_rendering;
243243

244-
if (r->state.clients.count) logr(info, "Using %lu render worker%s totaling %lu thread%s.\n", r->state.clients.count, PLURAL(r->state.clients.count), r->state.clients.count, PLURAL(r->state.clients.count));
244+
if (r->state.clients.count)
245+
logr(info, "Using %zu render worker%s totaling %zu thread%s.\n", r->state.clients.count, PLURAL(r->state.clients.count), r->state.clients.count, PLURAL(r->state.clients.count));
245246

246247
// Select the appropriate renderer type for local use
247248
void *(*local_render_thread)(void *) = render_thread;

0 commit comments

Comments
 (0)