diff --git a/ChangeLog b/ChangeLog index cedafeeffb..e9774f174c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Mon Aug 27 22:39:08 2007 Yukihiro Matsumoto + + * encoding.c (rb_enc_codelen): raises invalid sequence exception + if ONIGENC_CODE_TO_MBCLEN() returns zero. [ruby-dev:31661] + + * encoding.c (rb_enc_mbclen): check invalid sequence. + Mon Aug 27 20:27:59 2007 Masaki Suketa * ext/win32ole/win32ole.c (ole_type_progid): fix the bug. diff --git a/encoding.c b/encoding.c index eed384fb0d..fc0aa3b945 100644 --- a/encoding.c +++ b/encoding.c @@ -216,6 +216,26 @@ rb_enc_strlen(const char *p, const char *e, rb_encoding *enc) return c; } +int +rb_enc_mbclen(const char *p, rb_encoding *enc) +{ + int n = ONIGENC_MBC_ENC_LEN(enc, (UChar*)p); + if (n == 0) { + rb_raise(rb_eArgError, "invalid mbstring sequence"); + } + return n; +} + +int +rb_enc_codelen(int c, rb_encoding *enc) +{ + int n = ONIGENC_CODE_TO_MBCLEN(enc,c); + if (n == 0) { + rb_raise(rb_eArgError, "invalid mbstring sequence"); + } + return n; +} + int rb_enc_toupper(int c, rb_encoding *enc) { diff --git a/include/ruby/encoding.h b/include/ruby/encoding.h index 0fd2e3ce52..805209d15a 100644 --- a/include/ruby/encoding.h +++ b/include/ruby/encoding.h @@ -50,8 +50,10 @@ rb_encoding * rb_enc_find(const char *name); #define rb_enc_mbmaxlen(enc) (enc)->max_enc_len /* ptr,encoding -> mbclen */ -#define rb_enc_mbclen(p,enc) ONIGENC_MBC_ENC_LEN(enc, (UChar*)p) -#define rb_enc_codelen(c,enc) ONIGENC_CODE_TO_MBCLEN(enc,c) +int rb_enc_mbclen(const char*, rb_encoding*); + +/* code,encoding -> codelen */ +int rb_enc_codelen(int, rb_encoding*); /* code,ptr,encoding -> write buf */ #define rb_enc_mbcput(c,buf,enc) ONIGENC_CODE_TO_MBC(enc,c,(UChar*)buf)