Skip to content

Commit

Permalink
Updating the mysql2_mysql_enc_to_rb conversion table to 8.0 List (bri…
Browse files Browse the repository at this point in the history
…anmario#976)

Also add a check to make sure we do not go out of bounds.
  • Loading branch information
QuantamHD authored and hkmaly committed Oct 9, 2024
1 parent 59e446d commit 9581234
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ addons:
hosts:
- mysql2gem.example.com
apt:
update: true
packages:
- mysql-server-5.6
- mysql-client-core-5.6
Expand Down
10 changes: 10 additions & 0 deletions ext/mysql2/mysql_enc_to_ruby.h
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
3 changes: 2 additions & 1 deletion ext/mysql2/result.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,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);
Expand Down

0 comments on commit 9581234

Please sign in to comment.