Skip to content

Commit f6a862d

Browse files
author
Benjamin Weggenmann
committed
Fixed integer encoding on different architectures (32 and 64 bit).
[u]int64 is [unsigned] long *or* long long depending on the word size. Use inttypes.h macros (C99) to use correct encoding on all architectures.
1 parent 77a7636 commit f6a862d

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

protobuf-c-text/generate.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <stdio.h>
1616
#include <string.h>
1717
#include <stdlib.h>
18+
#include <inttypes.h>
1819
#include <protobuf-c/protobuf-c.h>
1920
#include "protobuf-c-text.h"
2021
#include "protobuf-c-util.h"
@@ -228,14 +229,14 @@ protobuf_c_text_to_string_internal(ReturnString *rs,
228229
for (j = 0; j < quantifier_offset; j++) {
229230
rs_append(rs, level + strlen(f[i].name) + 20,
230231
allocator,
231-
"%*s%s: %u\n",
232+
"%*s%s: %" PRIu32 "\n",
232233
level, "", f[i].name,
233234
STRUCT_MEMBER(uint32_t *, m, f[i].offset)[j]);
234235
}
235236
} else {
236237
rs_append(rs, level + strlen(f[i].name) + 20,
237238
allocator,
238-
"%*s%s: %u\n",
239+
"%*s%s: %" PRIu32 "\n",
239240
level, "", f[i].name,
240241
STRUCT_MEMBER(uint32_t, m, f[i].offset));
241242
}
@@ -247,14 +248,14 @@ protobuf_c_text_to_string_internal(ReturnString *rs,
247248
for (j = 0; j < quantifier_offset; j++) {
248249
rs_append(rs, level + strlen(f[i].name) + 20,
249250
allocator,
250-
"%*s%s: %d\n",
251+
"%*s%s: %" PRId32 "\n",
251252
level, "", f[i].name,
252253
STRUCT_MEMBER(int32_t *, m, f[i].offset)[j]);
253254
}
254255
} else {
255256
rs_append(rs, level + strlen(f[i].name) + 20,
256257
allocator,
257-
"%*s%s: %d\n",
258+
"%*s%s: %" PRId32 "\n",
258259
level, "", f[i].name,
259260
STRUCT_MEMBER(int32_t, m, f[i].offset));
260261
}
@@ -265,14 +266,14 @@ protobuf_c_text_to_string_internal(ReturnString *rs,
265266
for (j = 0; j < quantifier_offset; j++) {
266267
rs_append(rs, level + strlen(f[i].name) + 20,
267268
allocator,
268-
"%*s%s: %lu\n",
269+
"%*s%s: %" PRIu64 "\n",
269270
level, "", f[i].name,
270271
STRUCT_MEMBER(uint64_t *, m, f[i].offset)[j]);
271272
}
272273
} else {
273274
rs_append(rs, level + strlen(f[i].name) + 20,
274275
allocator,
275-
"%*s%s: %lu\n",
276+
"%*s%s: %" PRIu64 "\n",
276277
level, "", f[i].name,
277278
STRUCT_MEMBER(uint64_t, m, f[i].offset));
278279
}
@@ -284,14 +285,14 @@ protobuf_c_text_to_string_internal(ReturnString *rs,
284285
for (j = 0; j < quantifier_offset; j++) {
285286
rs_append(rs, level + strlen(f[i].name) + 20,
286287
allocator,
287-
"%*s%s: %ld\n",
288+
"%*s%s: %" PRId64 "\n",
288289
level, "", f[i].name,
289290
STRUCT_MEMBER(int64_t *, m, f[i].offset)[j]);
290291
}
291292
} else {
292293
rs_append(rs, level + strlen(f[i].name) + 20,
293294
allocator,
294-
"%*s%s: %ld\n",
295+
"%*s%s: %" PRId64 "\n",
295296
level, "", f[i].name,
296297
STRUCT_MEMBER(int64_t, m, f[i].offset));
297298
}

0 commit comments

Comments
 (0)