From 681acfd8ba3dea9b933ef594dafc7288b4d59320 Mon Sep 17 00:00:00 2001 From: Andy Wingo Date: Sun, 7 Aug 2016 23:20:00 +0200 Subject: [PATCH] Fix iconv encoding of long strings * libguile/print.c (display_string_using_iconv): If the encoding the full utf8 buffer would overflow the output buffer, just keep trucking instead of erroring. Fixes #22667. * test-suite/tests/iconv.test ("round-trip"): Add some tests. --- libguile/print.c | 6 +++++- test-suite/tests/iconv.test | 13 +++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/libguile/print.c b/libguile/print.c index 86e0a0367..a5b2a845b 100644 --- a/libguile/print.c +++ b/libguile/print.c @@ -1034,7 +1034,11 @@ display_string_using_iconv (const void *str, int narrow_p, size_t len, printed++; } - else + else if (errno_save == E2BIG) + /* No space in output buffer for this input. Keep + trucking. */ + continue; + else /* Something bad happened that we can't handle: bail out. */ break; } diff --git a/test-suite/tests/iconv.test b/test-suite/tests/iconv.test index 9083cd256..647761f04 100644 --- a/test-suite/tests/iconv.test +++ b/test-suite/tests/iconv.test @@ -118,3 +118,16 @@ (equal? (make-string (string-length s) #\?) (bytevector->string (string->bytevector s "ascii" 'substitute) "ascii"))))) + +(with-test-prefix "round-trip" + (define (pass-if-round-trip str encoding) + (pass-if-equal str str + (bytevector->string (string->bytevector str encoding) encoding))) + + (pass-if-round-trip (make-string 128 #\a) "UTF-8") + (pass-if-round-trip (make-string 128 #\a) "UTF-16") + (pass-if-round-trip (make-string 128 #\a) "UTF-32") + + (pass-if-round-trip (make-string 129 #\a) "UTF-8") + (pass-if-round-trip (make-string 129 #\a) "UTF-16") + (pass-if-round-trip (make-string 129 #\a) "UTF-32"))