From: David Levine Date: Sat, 1 Apr 2017 22:53:26 +0000 (-0400) Subject: Check for sufficient room for multi-column character. X-Git-Url: https://diplodocus.org/git/nmh/commitdiff_plain/80a9e99f7078199500d2d53c8d77d1b92af06fbc?ds=sidebyside;hp=7a8f0a82325e50ac3173faba501804aab0ad544e Check for sufficient room for multi-column character. Fix to commit 92128dacf8d5db02379e8f872dc50d31c6aaa55f. The sympton, reported by Valdis, was overrun of scan -width. --- diff --git a/sbr/fmt_scan.c b/sbr/fmt_scan.c index 1ea5e623..4416b54c 100644 --- a/sbr/fmt_scan.c +++ b/sbr/fmt_scan.c @@ -299,10 +299,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; diff --git a/test/scan/test-scan-multibyte b/test/scan/test-scan-multibyte index bab76b6c..dc2a284c 100755 --- a/test/scan/test-scan-multibyte +++ b/test/scan/test-scan-multibyte @@ -63,6 +63,8 @@ fi expected="$MH_TEST_DIR/$$.expected" actual="$MH_TEST_DIR/$$.actual" + +start_test 'RFC 2047 headers' if test "$width" -eq 3; then cat > "$expected" < $actual || exit 1 check "$expected" "$actual" + # # Check decoding with an invalid multibyte sequence. We skip this test # if we don't have iconv support, since it requires converting from one @@ -86,6 +89,7 @@ check "$expected" "$actual" # it's required for the test right after it. # +start_test 'invalid multibyte sequence' cat >`mhpath new` < To: Some User @@ -120,6 +124,7 @@ if test $? -ne 0; then fi # check scan width with a valid multibyte sequence +start_test 'scan width with a valid multibyte sequence' if test "$width" -eq 1; then cat >"$expected" <"$expected" <"$expected" <`mhpath new` <"$actual" +check "$expected" "$actual" + + +finish_test exit $failed