diff options
author | Joris Peeraer <jorispeeraer@gmail.com> | 2020-10-22 10:38:03 +0200 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2020-12-07 23:32:06 +1100 |
commit | 5020b14d5419065f1a5ef5aed1be7badee28c9bf (patch) | |
tree | 3a5ecda9ef9027206a3dbb4c3df5fab99803a32d /ports/unix/coverage.c | |
parent | dde0735ac1629aca4f7d41334f25b75dd8d35010 (diff) | |
download | micropython-5020b14d5419065f1a5ef5aed1be7badee28c9bf.tar.gz micropython-5020b14d5419065f1a5ef5aed1be7badee28c9bf.zip |
py/mpprint: Fix length calculation for strings with precision-modifier.
Two issues are tackled:
1. The calculation of the correct length to print is fixed to treat the
precision as a maximum length instead as the exact length.
This is done for both qstr (%q) and for regular str (%s).
2. Fix the incorrect use of mp_printf("%.*s") to mp_print_strn().
Because of the fix of above issue, some testcases that would print
an embedded null-byte (^@ in test-output) would now fail.
The bug here is that "%s" was used to print null-bytes. Instead,
mp_print_strn is used to make sure all bytes are outputted and the
exact length is respected.
Test-cases are added for both %s and %q with a combination of precision
and padding specifiers.
Diffstat (limited to 'ports/unix/coverage.c')
-rw-r--r-- | ports/unix/coverage.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/ports/unix/coverage.c b/ports/unix/coverage.c index 7169c7793b..ef66c4fb59 100644 --- a/ports/unix/coverage.c +++ b/ports/unix/coverage.c @@ -186,7 +186,7 @@ STATIC mp_obj_t extra_coverage(void) { mp_printf(&mp_plat_print, "%ld\n", 123); // long mp_printf(&mp_plat_print, "%lx\n", 0x123); // long hex mp_printf(&mp_plat_print, "%X\n", 0x1abcdef); // capital hex - mp_printf(&mp_plat_print, "%.2s %.3s\n", "abc", "abc"); // fixed string precision + mp_printf(&mp_plat_print, "%.2s %.3s '%4.4s' '%5.5q' '%.3q'\n", "abc", "abc", "abc", MP_QSTR_True, MP_QSTR_True); // fixed string precision mp_printf(&mp_plat_print, "%.*s\n", -1, "abc"); // negative string precision mp_printf(&mp_plat_print, "%b %b\n", 0, 1); // bools #ifndef NDEBUG |