Skip to content

Commit ef2552c

Browse files
Eric Wongbrianmario
Eric Wong
authored andcommitted
do not segfault when raising for invalid charset
There's no guarantee the user passed a string object, I encountered this when running tests under 1.9.3dev
1 parent 9f9e16d commit ef2552c

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

ext/mysql2/client.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,8 @@ static VALUE set_charset_name(VALUE self, VALUE value) {
586586
#ifdef HAVE_RUBY_ENCODING_H
587587
new_encoding = rb_funcall(cMysql2Client, intern_encoding_from_charset, 1, value);
588588
if (new_encoding == Qnil) {
589-
rb_raise(cMysql2Error, "Unsupported charset: '%s'", RSTRING_PTR(value));
589+
VALUE inspect = rb_inspect(value);
590+
rb_raise(cMysql2Error, "Unsupported charset: '%s'", RSTRING_PTR(inspect));
590591
} else {
591592
if (wrapper->encoding == Qnil) {
592593
wrapper->encoding = new_encoding;

0 commit comments

Comments
 (0)