Skip to content

Commit

Permalink
do not segfault when raising for invalid charset
Browse files Browse the repository at this point in the history
There's no guarantee the user passed a string object,
I encountered this when running tests under 1.9.3dev
  • Loading branch information
Eric Wong authored and brianmario committed Mar 25, 2011
1 parent 9f9e16d commit ef2552c
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion ext/mysql2/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,8 @@ static VALUE set_charset_name(VALUE self, VALUE value) {
#ifdef HAVE_RUBY_ENCODING_H
new_encoding = rb_funcall(cMysql2Client, intern_encoding_from_charset, 1, value);
if (new_encoding == Qnil) {
rb_raise(cMysql2Error, "Unsupported charset: '%s'", RSTRING_PTR(value));
VALUE inspect = rb_inspect(value);
rb_raise(cMysql2Error, "Unsupported charset: '%s'", RSTRING_PTR(inspect));
} else {
if (wrapper->encoding == Qnil) {
wrapper->encoding = new_encoding;
Expand Down

0 comments on commit ef2552c

Please sign in to comment.