i18n: Handle EINVAL more gracefully. 20100922040502/pspp 20100923040501/pspp
authorBen Pfaff <blp@cs.stanford.edu>
Tue, 21 Sep 2010 05:42:17 +0000 (22:42 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Wed, 22 Sep 2010 05:11:14 +0000 (22:11 -0700)
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.

src/libpspp/i18n.c

index d9b42cbcca844da31d46630c78295b8276591d99..60dc693db6585a967ddae3cc82c37f26455587eb 100644 (file)
@@ -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++;