Skip to content

Commit 46d6851

Browse files
QuantamHDsodabrew
authored andcommitted
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.
1 parent 4a20d58 commit 46d6851

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ addons:
1313
hosts:
1414
- mysql2gem.example.com
1515
apt:
16+
update: true
1617
packages:
1718
- mysql-server-5.6
1819
- mysql-client-core-5.6

ext/mysql2/mysql_enc_to_ruby.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,5 +245,15 @@ static const char *mysql2_mysql_enc_to_rb[] = {
245245
"UTF-8",
246246
"UTF-8",
247247
"UTF-8",
248+
"UTF-8",
249+
NULL,
250+
NULL,
251+
NULL,
252+
NULL,
253+
NULL,
254+
NULL,
255+
NULL,
248256
"UTF-8"
249257
};
258+
259+
#define CHARSETNR_SIZE (sizeof(mysql2_mysql_enc_to_rb)/sizeof(mysql2_mysql_enc_to_rb[0]))

ext/mysql2/result.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,8 @@ static VALUE mysql2_set_field_string_encoding(VALUE val, MYSQL_FIELD field, rb_e
179179
const char *enc_name;
180180
int enc_index;
181181

182-
enc_name = mysql2_mysql_enc_to_rb[field.charsetnr-1];
182+
enc_name = (field.charsetnr-1 < CHARSETNR_SIZE) ? mysql2_mysql_enc_to_rb[field.charsetnr-1] : NULL;
183+
183184
if (enc_name != NULL) {
184185
/* use the field encoding we were able to match */
185186
enc_index = rb_enc_find_index(enc_name);

0 commit comments

Comments
 (0)