aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--transcode.c48
2 files changed, 23 insertions, 31 deletions
diff --git a/ChangeLog b/ChangeLog
index 770e6dfd37..e888c284ad 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Sun Aug 10 22:34:55 2008 Tanaka Akira <akr@fsij.org>
+
+ * transcode.c (transcode_restartable0): invalid handling simplified.
+ (transcode_restartable): use PARTIAL_INPUT for converting buffered
+ input.
+
Sun Aug 10 22:24:24 2008 Yusuke Endoh <mame@tsg.ne.jp>
* encoding.c: include util.h. [ruby-dev:35715]
diff --git a/transcode.c b/transcode.c
index 3c1858d67d..317781b2ac 100644
--- a/transcode.c
+++ b/transcode.c
@@ -533,40 +533,26 @@ transcode_restartable0(const unsigned char **in_pos, unsigned char **out_pos,
break;
}
case INVALID:
- {
- if (tc->readlen + (in_p - inchar_start) <= unitlen) {
- while ((opt & PARTIAL_INPUT) && tc->readlen + (in_stop - inchar_start) < unitlen) {
- in_p = in_stop;
- SUSPEND(transcode_ibuf_empty, 8);
- }
- if (tc->readlen + (in_stop - inchar_start) <= unitlen) {
- in_p = in_stop;
- }
- else {
- in_p = inchar_start + (unitlen - tc->readlen);
- }
+ if (tc->readlen + (in_p - inchar_start) <= unitlen) {
+ while ((opt & PARTIAL_INPUT) && tc->readlen + (in_stop - inchar_start) < unitlen) {
+ in_p = in_stop;
+ SUSPEND(transcode_ibuf_empty, 8);
+ }
+ if (tc->readlen + (in_stop - inchar_start) <= unitlen) {
+ in_p = in_stop;
}
else {
- int found_len; /* including the last byte which cuases invalid */
- int invalid_len;
- int step;
- found_len = tc->readlen + (in_p - inchar_start);
- invalid_len = ((found_len - 1) / unitlen) * unitlen;
- step = invalid_len - found_len;
- if (step < -1) {
- if (-step <= in_p - *in_pos) {
- in_p += step;
- }
- else {
- feedlen = -step;
- }
- }
- else {
- in_p += step;
- }
+ in_p = inchar_start + (unitlen - tc->readlen);
}
- goto invalid;
}
+ else {
+ int invalid_len; /* including the last byte which causes invalid */
+ int discard_len;
+ invalid_len = tc->readlen + (in_p - inchar_start);
+ discard_len = ((invalid_len - 1) / unitlen) * unitlen;
+ feedlen = invalid_len - discard_len;
+ }
+ goto invalid;
case UNDEF:
goto undef;
}
@@ -608,7 +594,7 @@ transcode_restartable(const unsigned char **in_pos, unsigned char **out_pos,
MEMCPY(feed_buf, TRANSCODING_READBUF(tc) + tc->readlen,
unsigned char, tc->feedlen);
tc->feedlen = 0;
- res = transcode_restartable0(&feed_pos, out_pos, feed_stop, out_stop, tc, opt);
+ res = transcode_restartable0(&feed_pos, out_pos, feed_stop, out_stop, tc, opt|PARTIAL_INPUT);
if (res != transcode_ibuf_empty) {
MEMCPY(TRANSCODING_READBUF(tc) + tc->readlen + tc->feedlen,
feed_pos, unsigned char, feed_stop - feed_pos);