diff options
| author | Dan Halbert <halbert@halwitz.org> | 2018-11-09 23:35:22 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-11-09 23:35:22 -0500 |
| commit | 50f5d27c436cf71d14bf893709375e5bcf62717b (patch) | |
| tree | e44644757b48721a75d23b4794850124482f50c9 /lib | |
| parent | 97bc95183d5114ce69c9387ebd2e2aa13feb65a7 (diff) | |
| parent | d012fd155338641f1d54d68d04410a848e07319d (diff) | |
Merge pull request #1325 from tannewt/fix_overruns
Fix output overflow and make help translatable
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/utils/stdout_helpers.c | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/lib/utils/stdout_helpers.c b/lib/utils/stdout_helpers.c index 3de119757..4323e8a08 100644 --- a/lib/utils/stdout_helpers.c +++ b/lib/utils/stdout_helpers.c @@ -12,11 +12,21 @@ // Send "cooked" string of given length, where every occurrence of // LF character is replaced with CR LF. void mp_hal_stdout_tx_strn_cooked(const char *str, size_t len) { - while (len--) { - if (*str == '\n') { + bool last_cr = false; + while (len > 0) { + size_t i = 0; + if (str[0] == '\n' && !last_cr) { mp_hal_stdout_tx_strn("\r", 1); + i = 1; } - mp_hal_stdout_tx_strn(str++, 1); + // Lump all characters on the next line together. + while((last_cr || str[i] != '\n') && i < len) { + last_cr = str[i] == '\r'; + i++; + } + mp_hal_stdout_tx_strn(str, i); + str = &str[i]; + len -= i; } } |
