Skip to content

Commit 4cc4625

Browse files
authored
Cleanup output format warnings (#904)
Use `PRIxxx` related macros to format the output strings so as to clear compile warnings, e.g. PRIu32, PRId32, PRIX32, PRIX64 and so on. And add the related macro definitions in platform_common.h if they are not defined, as some compilers might not support them.
1 parent a41c1ad commit 4cc4625

File tree

9 files changed

+74
-26
lines changed

9 files changed

+74
-26
lines changed

core/iwasm/aot/arch/aot_reloc_riscv.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ apply_relocation(AOTModule *module, uint8 *target_section_addr,
357357
if (error_buf != NULL)
358358
snprintf(error_buf, error_buf_size,
359359
"Load relocation section failed: "
360-
"invalid relocation type %d.",
360+
"invalid relocation type %" PRIu32 ".",
361361
reloc_type);
362362
return false;
363363
}

core/iwasm/common/wasm_application.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ wasm_application_execute_func(WASMModuleInstanceCommon *module_inst,
417417
char *endptr = NULL;
418418
bh_assert(argv[i] != NULL);
419419
if (argv[i][0] == '\0') {
420-
snprintf(buf, sizeof(buf), "invalid input argument %d", i);
420+
snprintf(buf, sizeof(buf), "invalid input argument %" PRId32, i);
421421
wasm_runtime_set_exception(module_inst, buf);
422422
goto fail;
423423
}
@@ -554,8 +554,8 @@ wasm_application_execute_func(WASMModuleInstanceCommon *module_inst,
554554
break;
555555
}
556556
if (endptr && *endptr != '\0' && *endptr != '_') {
557-
snprintf(buf, sizeof(buf), "invalid input argument %d: %s", i,
558-
argv[i]);
557+
snprintf(buf, sizeof(buf), "invalid input argument %" PRId32 ": %s",
558+
i, argv[i]);
559559
wasm_runtime_set_exception(module_inst, buf);
560560
goto fail;
561561
}
@@ -573,7 +573,7 @@ wasm_application_execute_func(WASMModuleInstanceCommon *module_inst,
573573
switch (type->types[type->param_count + j]) {
574574
case VALUE_TYPE_I32:
575575
{
576-
os_printf("0x%x:i32", argv1[k]);
576+
os_printf("0x%" PRIx32 ":i32", argv1[k]);
577577
k++;
578578
break;
579579
}

core/iwasm/compilation/aot_llvm.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2490,12 +2490,12 @@ aot_load_const_from_table(AOTCompContext *comp_ctx, LLVMValueRef base,
24902490
switch (value_type) {
24912491
case VALUE_TYPE_F32:
24922492
/* Store the raw int bits of f32 const as a hex string */
2493-
snprintf(buf, sizeof(buf), "f32#%08X", value->i32);
2493+
snprintf(buf, sizeof(buf), "f32#%08" PRIX32, value->i32);
24942494
const_ptr_type = F32_PTR_TYPE;
24952495
break;
24962496
case VALUE_TYPE_F64:
24972497
/* Store the raw int bits of f64 const as a hex string */
2498-
snprintf(buf, sizeof(buf), "f64#%016" PRIx64, value->i64);
2498+
snprintf(buf, sizeof(buf), "f64#%016" PRIX64, value->i64);
24992499
const_ptr_type = F64_PTR_TYPE;
25002500
break;
25012501
default:

core/iwasm/interpreter/wasm_interp_fast.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3733,8 +3733,9 @@ wasm_interp_call_wasm(WASMModuleInstance *module_inst, WASMExecEnv *exec_env,
37333733
if (argc < function->param_cell_num) {
37343734
char buf[128];
37353735
snprintf(buf, sizeof(buf),
3736-
"invalid argument count %u, must be no smaller than %u", argc,
3737-
function->param_cell_num);
3736+
"invalid argument count %" PRIu32
3737+
", must be no smaller than %" PRIu32,
3738+
argc, (uint32)function->param_cell_num);
37383739
wasm_set_exception(module_inst, buf);
37393740
return;
37403741
}

core/iwasm/libraries/libc-builtin/libc_builtin_wrapper.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,7 @@ exit_wrapper(wasm_exec_env_t exec_env, int32 status)
769769
{
770770
wasm_module_inst_t module_inst = get_module_inst(exec_env);
771771
char buf[32];
772-
snprintf(buf, sizeof(buf), "env.exit(%i)", status);
772+
snprintf(buf, sizeof(buf), "env.exit(%" PRId32 ")", status);
773773
wasm_runtime_set_exception(module_inst, buf);
774774
}
775775

@@ -1012,7 +1012,7 @@ abort_wrapper(wasm_exec_env_t exec_env, int32 code)
10121012
{
10131013
wasm_module_inst_t module_inst = get_module_inst(exec_env);
10141014
char buf[32];
1015-
snprintf(buf, sizeof(buf), "env.abort(%i)", code);
1015+
snprintf(buf, sizeof(buf), "env.abort(%" PRId32 ")", code);
10161016
wasm_runtime_set_exception(module_inst, buf);
10171017
}
10181018

@@ -1021,7 +1021,7 @@ abortStackOverflow_wrapper(wasm_exec_env_t exec_env, int32 code)
10211021
{
10221022
wasm_module_inst_t module_inst = get_module_inst(exec_env);
10231023
char buf[32];
1024-
snprintf(buf, sizeof(buf), "env.abortStackOverflow(%i)", code);
1024+
snprintf(buf, sizeof(buf), "env.abortStackOverflow(%" PRId32 ")", code);
10251025
wasm_runtime_set_exception(module_inst, buf);
10261026
}
10271027

@@ -1030,7 +1030,7 @@ nullFunc_X_wrapper(wasm_exec_env_t exec_env, int32 code)
10301030
{
10311031
wasm_module_inst_t module_inst = get_module_inst(exec_env);
10321032
char buf[32];
1033-
snprintf(buf, sizeof(buf), "env.nullFunc_X(%i)", code);
1033+
snprintf(buf, sizeof(buf), "env.nullFunc_X(%" PRId32 ")", code);
10341034
wasm_runtime_set_exception(module_inst, buf);
10351035
}
10361036

core/shared/mem-alloc/ems/ems_alloc.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,8 @@ void
722722
gc_dump_heap_stats(gc_heap_t *heap)
723723
{
724724
os_printf("heap: %p, heap start: %p\n", heap, heap->base_addr);
725-
os_printf("total free: %u, current: %u, highmark: %u\n",
725+
os_printf("total free: %" PRIu32 ", current: %" PRIu32
726+
", highmark: %" PRIu32 "\n",
726727
heap->total_free_size, heap->current_size, heap->highmark_size);
727728
os_printf("g_total_malloc=%lu, g_total_free=%lu, occupied=%lu\n",
728729
g_total_malloc, g_total_free, g_total_malloc - g_total_free);
@@ -765,9 +766,10 @@ gci_dump(gc_heap_t *heap)
765766
return;
766767
}
767768

768-
os_printf("#%d %08x %x %x %d %c %d\n", i,
769-
(int32)((char *)cur - (char *)heap->base_addr), ut, p, mark,
770-
inuse, (int32)hmu_obj_size(size));
769+
os_printf("#%d %08" PRIx32 " %" PRIx32 " %d %d"
770+
" %c %" PRId32 "\n",
771+
i, (int32)((char *)cur - (char *)heap->base_addr), (int32)ut,
772+
p, mark, inuse, (int32)hmu_obj_size(size));
771773
#if BH_ENABLE_GC_VERIFY != 0
772774
if (inuse == 'V') {
773775
gc_object_prefix_t *prefix = (gc_object_prefix_t *)(cur + 1);

core/shared/mem-alloc/ems/ems_kfc.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ gc_init_with_pool(char *buf, gc_size_t buf_size)
5959
gc_size_t heap_max_size;
6060

6161
if (buf_size < APP_HEAP_SIZE_MIN) {
62-
os_printf("[GC_ERROR]heap init buf size (%u) < %u\n", buf_size,
63-
APP_HEAP_SIZE_MIN);
62+
os_printf("[GC_ERROR]heap init buf size (%" PRIu32 ") < %" PRIu32 "\n",
63+
buf_size, (uint32)APP_HEAP_SIZE_MIN);
6464
return NULL;
6565
}
6666

@@ -93,7 +93,7 @@ gc_init_with_struct_and_pool(char *struct_buf, gc_size_t struct_buf_size,
9393
}
9494

9595
if (struct_buf_size < sizeof(gc_handle_t)) {
96-
os_printf("[GC_ERROR]heap init struct buf size (%u) < %zu\n",
96+
os_printf("[GC_ERROR]heap init struct buf size (%" PRIu32 ") < %zu\n",
9797
struct_buf_size, sizeof(gc_handle_t));
9898
return NULL;
9999
}
@@ -104,8 +104,8 @@ gc_init_with_struct_and_pool(char *struct_buf, gc_size_t struct_buf_size,
104104
}
105105

106106
if (pool_buf_size < APP_HEAP_SIZE_MIN) {
107-
os_printf("[GC_ERROR]heap init buf size (%u) < %u\n", pool_buf_size,
108-
APP_HEAP_SIZE_MIN);
107+
os_printf("[GC_ERROR]heap init buf size (%" PRIu32 ") < %u\n",
108+
pool_buf_size, APP_HEAP_SIZE_MIN);
109109
return NULL;
110110
}
111111

core/shared/platform/include/platform_common.h

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,48 @@ typedef int64_t int64;
104104

105105
typedef void *(*thread_start_routine_t)(void *);
106106

107+
#ifndef PRId32
108+
#define PRId32 "d"
109+
#endif
110+
#ifndef PRIi32
111+
#define PRIi32 "i"
112+
#endif
113+
#ifndef PRIu32
114+
#define PRIu32 "u"
115+
#endif
116+
#ifndef PRIx32
117+
#define PRIx32 "x"
118+
#endif
119+
#ifndef PRIX32
120+
#define PRIX32 "X"
121+
#endif
122+
123+
#ifndef __PRI64_PREFIX
124+
#if UINTPTR_MAX == UINT64_MAX
125+
#define __PRI64_PREFIX "l"
126+
#define __PRIPTR_PREFIX "l"
127+
#else
128+
#define __PRI64_PREFIX "ll"
129+
#define __PRIPTR_PREFIX
130+
#endif
131+
#endif
132+
133+
#ifndef PRId64
134+
#define PRId64 __PRI64_PREFIX "d"
135+
#endif
136+
#ifndef PRIu64
137+
#define PRIu64 __PRI64_PREFIX "u"
138+
#endif
139+
#ifndef PRIx64
140+
#define PRIx64 __PRI64_PREFIX "x"
141+
#endif
142+
#ifndef PRIX64
143+
#define PRIX64 __PRI64_PREFIX "X"
144+
#endif
145+
#ifndef PRIXPTR
146+
#define PRIXPTR __PRIPTR_PREFIX "X"
147+
#endif
148+
107149
#ifdef __cplusplus
108150
}
109151
#endif

core/shared/utils/bh_log.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,11 @@ bh_log(LogLevel log_level, const char *file, int line, const char *fmt, ...)
3939
s = t % 60;
4040
mills = (uint32)(usec % 1000);
4141

42-
snprintf(buf, sizeof(buf), "%02u:%02u:%02u:%03u", h, m, s, mills);
42+
snprintf(buf, sizeof(buf),
43+
"%02" PRIu32 ":%02" PRIu32 ":%02" PRIu32 ":%03" PRIu32, h, m, s,
44+
mills);
4345

44-
os_printf("[%s - %X]: ", buf, (uint32)(uintptr_t)self);
46+
os_printf("[%s - %" PRIXPTR "]: ", buf, (uintptr_t)self);
4547

4648
if (file)
4749
os_printf("%s, line %d, ", file, line);
@@ -71,8 +73,9 @@ bh_print_time(const char *prompt)
7173

7274
total_time_ms += curr_time_ms - last_time_ms;
7375

74-
os_printf("%-48s time of last stage: %u ms, total time: %u ms\n", prompt,
75-
curr_time_ms - last_time_ms, total_time_ms);
76+
os_printf("%-48s time of last stage: %" PRIu32 " ms, total time: %" PRIu32
77+
" ms\n",
78+
prompt, curr_time_ms - last_time_ms, total_time_ms);
7679

7780
last_time_ms = curr_time_ms;
7881
}

0 commit comments

Comments
 (0)