Project

General

Profile

Bug #669 » fix-segv-by-iconv-new-with-not-string.diff

hiroshi (Hiroshi MORIYAMA), 10/21/2008 07:06 AM

View differences:

ext/iconv/iconv.c (working copy)
static VALUE
strip_glibc_option(VALUE *code)
{
VALUE val = *code;
VALUE val = StringValue(*code);
const char *ptr = RSTRING_PTR(val), *pend = RSTRING_END(val);
const char *slash = memchr(ptr, '/', pend - ptr);
if (slash && slash < pend - 1 && slash[1] == '/') {
VALUE opt = rb_str_subseq(val, slash - ptr, pend - slash);
val = rb_str_subseq(val, 0, slash - ptr);
......
static char *
map_charset(VALUE *code)
{
VALUE val = *code;
VALUE val = StringValue(*code);
if (RHASH_SIZE(charset_map)) {
VALUE key = rb_funcall2(val, rb_intern("downcase"), 0, 0);
......
static iconv_t
iconv_create(VALUE to, VALUE from, struct rb_iconv_opt_t *opt, int *idx)
{
VALUE toopt = strip_glibc_option(&to);
VALUE fromopt = strip_glibc_option(&from);
VALUE toopt, fromopt;
VALUE toenc = 0, fromenc = 0;
const char* tocode = map_charset(&to);
const char* fromcode = map_charset(&from);
const char *tocode, *fromcode;
iconv_t cd;
int retry = 0;
to = StringValue(to);
from = StringValue(from);
toopt = strip_glibc_option(&to);
fromopt = strip_glibc_option(&from);
tocode = map_charset(&to);
fromcode = map_charset(&from);
*idx = rb_enc_find_index(tocode);
if (toopt) {
test/iconv/test_basic.rb (working copy)
assert_equal("#{SJIS_STR}\n"*2, output)
end
def test_invalid_arguments
assert_raise(TypeError) { Iconv.new(nil, 'Shift_JIS') }
assert_raise(TypeError) { Iconv.new('Shift_JIS', nil) }
assert_raise(TypeError) { Iconv.open(nil, 'Shift_JIS') }
assert_raise(TypeError) { Iconv.open('Shift_JIS', nil) }
end
def test_unknown_encoding
assert_raise(Iconv::InvalidEncoding) { Iconv.iconv("utf-8", "X-UKNOWN", "heh") }
end
    (1-1/1)