[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[i18n 6/6] i18n: Handle EINVAL more gracefully.
From: |
Ben Pfaff |
Subject: |
[i18n 6/6] i18n: Handle EINVAL more gracefully. |
Date: |
Mon, 20 Sep 2010 22:50:26 -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 | 9 +++++++--
1 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/src/libpspp/i18n.c b/src/libpspp/i18n.c
index d9b42cb..60dc693 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++;
--
1.7.1
- [i18n 0/6] Fixes for recode_string()., Ben Pfaff, 2010/09/21
- [i18n 3/6] i18n: Ensure that every recoding starts from the initial shift state., Ben Pfaff, 2010/09/21
- [i18n 4/6] i18n: Properly restart conversion when output buffer overflows., Ben Pfaff, 2010/09/21
- [i18n 5/6] i18n: Refactor for simplicity., Ben Pfaff, 2010/09/21
- [i18n 1/6] i18n: Lightly reformat comments to better resemble other files., Ben Pfaff, 2010/09/21
- [i18n 6/6] i18n: Handle EINVAL more gracefully.,
Ben Pfaff <=
- [i18n 2/6] i18n: Avoid memory leak when create_iconv() fails., Ben Pfaff, 2010/09/21
- Re: [i18n 0/6] Fixes for recode_string()., John Darrington, 2010/09/21