From: Ben Pfaff Date: Tue, 21 Sep 2010 05:42:17 +0000 (-0700) Subject: i18n: Handle EINVAL more gracefully. X-Git-Tag: sav-api~26 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?p=pspp;a=commitdiff_plain;h=2b84fc2b70df7767ee9a279fffab5db1b3c8023e i18n: Handle EINVAL more gracefully. EINVAL indicates an invalid multibyte sequence at the end of buffer. It seems to me that there is no point in swallowing up a single byte and going on at that point; instead, one might as well just declare the conversion done after adding the fallback character. This is what this commit does. --- diff --git a/src/libpspp/i18n.c b/src/libpspp/i18n.c index d9b42cbcca..60dc693db6 100644 --- a/src/libpspp/i18n.c +++ b/src/libpspp/i18n.c @@ -118,11 +118,16 @@ try_recode (iconv_t conv, &op, &outbytes) == -1) switch (errno) { - case EILSEQ: case EINVAL: - if (outbytes == 0) + if (outbytes < 2) return false; + *op++ = fallbackchar; + *op++ = '\0'; + return true; + case EILSEQ: + if (outbytes == 0) + return false; *op++ = fallbackchar; outbytes--; ip++;