[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[i18n 4/6] i18n: Properly restart conversion when output buffer overflow
From: |
Ben Pfaff |
Subject: |
[i18n 4/6] i18n: Properly restart conversion when output buffer overflows. |
Date: |
Mon, 20 Sep 2010 22:50:24 -0700 |
The E2BIG case tries to restart the whole conversion, by reinitializing
all variables to their initial states. However the value of 'text' might
already have been advanced somewhat if there was a previous loop for e.g.
an invalid character. This commit fixes the problem by keeping the
original 'text' around and using a moving input pointer instead.
---
src/libpspp/i18n.c | 8 +++++---
1 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/src/libpspp/i18n.c b/src/libpspp/i18n.c
index 06c67d9..fa9f29c 100644
--- a/src/libpspp/i18n.c
+++ b/src/libpspp/i18n.c
@@ -117,6 +117,7 @@ recode_string_pool (const char *to, const char *from,
char *outbuf = 0;
size_t outbufferlength;
size_t result;
+ char *ip;
char *op ;
size_t inbytes = 0;
size_t outbytes ;
@@ -150,6 +151,8 @@ recode_string_pool (const char *to, const char *from,
if ( outbufferlength > length)
break;
+ ip = text;
+
outbuf = pool_malloc (pool, outbufferlength);
op = outbuf;
@@ -158,8 +161,7 @@ recode_string_pool (const char *to, const char *from,
do {
- const char *ip = text;
- result = iconv (conv, (ICONV_CONST char **) &text, &inbytes,
+ result = iconv (conv, (ICONV_CONST char **) &ip, &inbytes,
&op, &outbytes);
if ( -1 == result )
@@ -187,7 +189,7 @@ recode_string_pool (const char *to, const char *from,
op = outbuf;
outbytes = outbufferlength;
inbytes = length;
- text = ip;
+ ip = text;
break;
default:
/* should never happen */
--
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 <=
- [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, 2010/09/21
- [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