aboutsummaryrefslogtreecommitdiffstats
path: root/encoding.c
diff options
context:
space:
mode:
Diffstat (limited to 'encoding.c')
-rw-r--r--encoding.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/encoding.c b/encoding.c
index e902f6db0e..21b56f2636 100644
--- a/encoding.c
+++ b/encoding.c
@@ -496,9 +496,13 @@ rb_enc_mbclen(const char *p, const char *e, rb_encoding *enc)
int
rb_enc_precise_mbclen(const char *p, const char *e, rb_encoding *enc)
{
+ int n;
if (e <= p)
return ONIGENC_CONSTRUCT_MBCLEN_NEEDMORE(1);
- return ONIGENC_PRECISE_MBC_ENC_LEN(enc, (UChar*)p, (UChar*)e);
+ n = ONIGENC_PRECISE_MBC_ENC_LEN(enc, (UChar*)p, (UChar*)e);
+ if (e-p < n)
+ return ONIGENC_CONSTRUCT_MBCLEN_NEEDMORE(n-(e-p));
+ return n;
}
int rb_enc_get_ascii(const char *p, const char *e, rb_encoding *enc)