X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/044363451d877b3c9a278db74763c6c9991e49f0..7ec0c9a0229aa160d7419922d2f4ba7e87480cd6:/sbr/fmt_scan.c diff --git a/sbr/fmt_scan.c b/sbr/fmt_scan.c index 1ea5e623..ef3ab1b1 100644 --- a/sbr/fmt_scan.c +++ b/sbr/fmt_scan.c @@ -1,6 +1,4 @@ - -/* - * fmt_scan.c -- format string interpretation +/* fmt_scan.c -- format string interpretation * * This code is Copyright (c) 2002, by the authors of nmh. See the * COPYRIGHT file in the root directory of the nmh distribution for @@ -299,10 +297,20 @@ cpstripped (charstring_t dest, size_t max, char *str) prevCtrl = 0; #ifdef MULTIBYTE_SUPPORT - charstring_push_back_chars (dest, altstr ? altstr : str, char_len, w); - max -= w; - str += char_len; - altstr = NULL; + assert(w >= 0); + if (max >= (size_t) w) { + charstring_push_back_chars (dest, altstr ? altstr : str, char_len, w); + max -= w; + str += char_len; + altstr = NULL; + } else { + /* Not enough width available for the last character. Output + space(s) to fill. */ + while (max-- > 0) { + charstring_push_back (dest, ' '); + } + break; + } #else /* MULTIBYE_SUPPORT */ charstring_push_back (dest, *str++); --max; @@ -825,7 +833,7 @@ fmt_scan (struct format *format, charstring_t scanlp, int width, int *dat, } break; case FT_LV_ZONEF: - if ((fmt->f_comp->c_tws->tw_flags & TW_SZONE) == TW_SZEXP) + if (fmt->f_comp->c_tws->tw_flags & TW_SZEXP) value = 1; else value = -1;