From 46d6851d8b82862965e3fd01aaa27996b50daa58 Mon Sep 17 00:00:00 2001 From: Ethan Mahintorabi Date: Fri, 18 May 2018 14:21:48 -0700 Subject: [PATCH] Updating the mysql2_mysql_enc_to_rb conversion table to 8.0 List (#976) Also add a check to make sure we do not go out of bounds. --- .travis.yml | 1 + ext/mysql2/mysql_enc_to_ruby.h | 10 ++++++++++ ext/mysql2/result.c | 3 ++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index a8661f785..396e00929 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,6 +13,7 @@ addons: hosts: - mysql2gem.example.com apt: + update: true packages: - mysql-server-5.6 - mysql-client-core-5.6 diff --git a/ext/mysql2/mysql_enc_to_ruby.h b/ext/mysql2/mysql_enc_to_ruby.h index df167b2a6..985fdfeeb 100644 --- a/ext/mysql2/mysql_enc_to_ruby.h +++ b/ext/mysql2/mysql_enc_to_ruby.h @@ -245,5 +245,15 @@ static const char *mysql2_mysql_enc_to_rb[] = { "UTF-8", "UTF-8", "UTF-8", + "UTF-8", + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, "UTF-8" }; + +#define CHARSETNR_SIZE (sizeof(mysql2_mysql_enc_to_rb)/sizeof(mysql2_mysql_enc_to_rb[0])) diff --git a/ext/mysql2/result.c b/ext/mysql2/result.c index a4957ee42..0ab38aabe 100644 --- a/ext/mysql2/result.c +++ b/ext/mysql2/result.c @@ -179,7 +179,8 @@ static VALUE mysql2_set_field_string_encoding(VALUE val, MYSQL_FIELD field, rb_e const char *enc_name; int enc_index; - enc_name = mysql2_mysql_enc_to_rb[field.charsetnr-1]; + enc_name = (field.charsetnr-1 < CHARSETNR_SIZE) ? mysql2_mysql_enc_to_rb[field.charsetnr-1] : NULL; + if (enc_name != NULL) { /* use the field encoding we were able to match */ enc_index = rb_enc_find_index(enc_name);