Skip to content

Commit db7e935

Browse files
jeplerdpgeorge
authored andcommitted
unix/coverage: Cast values to int for format printing.
During the coverage test, all the values encountered are within the range of `%d`. These locations were found using an experimental gcc plugin for `mp_printf` error checking. Signed-off-by: Jeff Epler <[email protected]>
1 parent 61006d8 commit db7e935

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

ports/unix/coverage.c

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -171,13 +171,13 @@ static void pairheap_test(size_t nops, int *ops) {
171171
if (mp_pairheap_is_empty(pairheap_lt, heap)) {
172172
mp_printf(&mp_plat_print, " -");
173173
} else {
174-
mp_printf(&mp_plat_print, " %d", mp_pairheap_peek(pairheap_lt, heap) - &node[0]);
174+
mp_printf(&mp_plat_print, " %d", (int)(mp_pairheap_peek(pairheap_lt, heap) - &node[0]));
175175
;
176176
}
177177
}
178178
mp_printf(&mp_plat_print, "\npop all:");
179179
while (!mp_pairheap_is_empty(pairheap_lt, heap)) {
180-
mp_printf(&mp_plat_print, " %d", mp_pairheap_peek(pairheap_lt, heap) - &node[0]);
180+
mp_printf(&mp_plat_print, " %d", (int)(mp_pairheap_peek(pairheap_lt, heap) - &node[0]));
181181
;
182182
heap = mp_pairheap_pop(pairheap_lt, heap);
183183
}
@@ -274,7 +274,7 @@ static mp_obj_t extra_coverage(void) {
274274
mp_printf(&mp_plat_print, "%p\n", gc_realloc(p, 0, false));
275275

276276
// calling gc_nbytes with a non-heap pointer
277-
mp_printf(&mp_plat_print, "%p\n", gc_nbytes(NULL));
277+
mp_printf(&mp_plat_print, "%d\n", (int)gc_nbytes(NULL));
278278
}
279279

280280
// GC initialisation and allocation stress test, to check the logic behind ALLOC_TABLE_GAP_BYTE
@@ -335,7 +335,7 @@ static mp_obj_t extra_coverage(void) {
335335
}
336336
ptrs[i][j] = j;
337337
}
338-
mp_printf(&mp_plat_print, "%d %d\n", i, all_zero);
338+
mp_printf(&mp_plat_print, "%d %d\n", (int)i, (int)all_zero);
339339

340340
// hide the pointer from the GC and collect
341341
ptrs[i] = FLIP_POINTER(ptrs[i]);
@@ -351,7 +351,7 @@ static mp_obj_t extra_coverage(void) {
351351
break;
352352
}
353353
}
354-
mp_printf(&mp_plat_print, "%d %d\n", i, correct_contents);
354+
mp_printf(&mp_plat_print, "%d %d\n", (int)i, (int)correct_contents);
355355
}
356356

357357
// free the memory blocks
@@ -449,7 +449,7 @@ static mp_obj_t extra_coverage(void) {
449449
// create a bytearray via mp_obj_new_bytearray
450450
mp_buffer_info_t bufinfo;
451451
mp_get_buffer_raise(mp_obj_new_bytearray(4, "data"), &bufinfo, MP_BUFFER_RW);
452-
mp_printf(&mp_plat_print, "%.*s\n", bufinfo.len, bufinfo.buf);
452+
mp_printf(&mp_plat_print, "%.*s\n", (int)bufinfo.len, bufinfo.buf);
453453
}
454454

455455
// mpz
@@ -516,11 +516,11 @@ static mp_obj_t extra_coverage(void) {
516516

517517
// hash the zero mpz integer
518518
mpz_set_from_int(&mpz, 0);
519-
mp_printf(&mp_plat_print, "%d\n", mpz_hash(&mpz));
519+
mp_printf(&mp_plat_print, "%d\n", (int)mpz_hash(&mpz));
520520

521521
// convert the mpz zero integer to int
522522
mp_printf(&mp_plat_print, "%d\n", mpz_as_int_checked(&mpz, &value_signed));
523-
mp_printf(&mp_plat_print, "%d\n", value_signed);
523+
mp_printf(&mp_plat_print, "%d\n", (int)value_signed);
524524

525525
// mpz_set_from_float with 0 as argument
526526
mpz_set_from_float(&mpz, 0);
@@ -562,7 +562,7 @@ static mp_obj_t extra_coverage(void) {
562562
mp_call_function_2_protected(MP_OBJ_FROM_PTR(&mp_builtin_divmod_obj), mp_obj_new_str_from_cstr("abc"), mp_obj_new_str_from_cstr("abc"));
563563

564564
// mp_obj_int_get_checked with mp_obj_int_t that has a value that is a small integer
565-
mp_printf(&mp_plat_print, "%d\n", mp_obj_int_get_checked(MP_OBJ_FROM_PTR(mp_obj_int_new_mpz())));
565+
mp_printf(&mp_plat_print, "%d\n", (int)mp_obj_int_get_checked(MP_OBJ_FROM_PTR(mp_obj_int_new_mpz())));
566566

567567
// mp_obj_int_get_uint_checked with non-negative small-int
568568
mp_printf(&mp_plat_print, "%d\n", (int)mp_obj_int_get_uint_checked(MP_OBJ_NEW_SMALL_INT(1)));
@@ -674,7 +674,7 @@ static mp_obj_t extra_coverage(void) {
674674
#endif
675675

676676
mp_vm_return_kind_t ret = mp_execute_bytecode(code_state, MP_OBJ_NULL);
677-
mp_printf(&mp_plat_print, "%d %d\n", ret, mp_obj_get_type(code_state->state[0]) == &mp_type_NotImplementedError);
677+
mp_printf(&mp_plat_print, "%d %d\n", (int)ret, mp_obj_get_type(code_state->state[0]) == &mp_type_NotImplementedError);
678678
}
679679

680680
// scheduler
@@ -754,36 +754,36 @@ static mp_obj_t extra_coverage(void) {
754754
mp_printf(&mp_plat_print, "# ringbuf\n");
755755

756756
// Single-byte put/get with empty ringbuf.
757-
mp_printf(&mp_plat_print, "%d %d\n", ringbuf_free(&ringbuf), ringbuf_avail(&ringbuf));
757+
mp_printf(&mp_plat_print, "%d %d\n", (int)ringbuf_free(&ringbuf), (int)ringbuf_avail(&ringbuf));
758758
ringbuf_put(&ringbuf, 22);
759-
mp_printf(&mp_plat_print, "%d %d\n", ringbuf_free(&ringbuf), ringbuf_avail(&ringbuf));
759+
mp_printf(&mp_plat_print, "%d %d\n", (int)ringbuf_free(&ringbuf), (int)ringbuf_avail(&ringbuf));
760760
mp_printf(&mp_plat_print, "%d\n", ringbuf_get(&ringbuf));
761-
mp_printf(&mp_plat_print, "%d %d\n", ringbuf_free(&ringbuf), ringbuf_avail(&ringbuf));
761+
mp_printf(&mp_plat_print, "%d %d\n", (int)ringbuf_free(&ringbuf), (int)ringbuf_avail(&ringbuf));
762762

763763
// Two-byte put/get with empty ringbuf.
764764
ringbuf_put16(&ringbuf, 0xaa55);
765-
mp_printf(&mp_plat_print, "%d %d\n", ringbuf_free(&ringbuf), ringbuf_avail(&ringbuf));
765+
mp_printf(&mp_plat_print, "%d %d\n", (int)ringbuf_free(&ringbuf), (int)ringbuf_avail(&ringbuf));
766766
mp_printf(&mp_plat_print, "%04x\n", ringbuf_get16(&ringbuf));
767-
mp_printf(&mp_plat_print, "%d %d\n", ringbuf_free(&ringbuf), ringbuf_avail(&ringbuf));
767+
mp_printf(&mp_plat_print, "%d %d\n", (int)ringbuf_free(&ringbuf), (int)ringbuf_avail(&ringbuf));
768768

769769
// Two-byte put with full ringbuf.
770770
for (int i = 0; i < 99; ++i) {
771771
ringbuf_put(&ringbuf, i);
772772
}
773-
mp_printf(&mp_plat_print, "%d %d\n", ringbuf_free(&ringbuf), ringbuf_avail(&ringbuf));
773+
mp_printf(&mp_plat_print, "%d %d\n", (int)ringbuf_free(&ringbuf), (int)ringbuf_avail(&ringbuf));
774774
mp_printf(&mp_plat_print, "%d\n", ringbuf_put16(&ringbuf, 0x11bb));
775775
// Two-byte put with one byte free.
776776
ringbuf_get(&ringbuf);
777-
mp_printf(&mp_plat_print, "%d %d\n", ringbuf_free(&ringbuf), ringbuf_avail(&ringbuf));
777+
mp_printf(&mp_plat_print, "%d %d\n", (int)ringbuf_free(&ringbuf), (int)ringbuf_avail(&ringbuf));
778778
mp_printf(&mp_plat_print, "%d\n", ringbuf_put16(&ringbuf, 0x3377));
779779
ringbuf_get(&ringbuf);
780-
mp_printf(&mp_plat_print, "%d %d\n", ringbuf_free(&ringbuf), ringbuf_avail(&ringbuf));
780+
mp_printf(&mp_plat_print, "%d %d\n", (int)ringbuf_free(&ringbuf), (int)ringbuf_avail(&ringbuf));
781781
mp_printf(&mp_plat_print, "%d\n", ringbuf_put16(&ringbuf, 0xcc99));
782782
for (int i = 0; i < 97; ++i) {
783783
ringbuf_get(&ringbuf);
784784
}
785785
mp_printf(&mp_plat_print, "%04x\n", ringbuf_get16(&ringbuf));
786-
mp_printf(&mp_plat_print, "%d %d\n", ringbuf_free(&ringbuf), ringbuf_avail(&ringbuf));
786+
mp_printf(&mp_plat_print, "%d %d\n", (int)ringbuf_free(&ringbuf), (int)ringbuf_avail(&ringbuf));
787787

788788
// Two-byte put with wrap around on first byte:
789789
ringbuf.iput = 0;

0 commit comments

Comments
 (0)