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 kamibayashi committed Mar 7, 2023
1 parent 2080e4b commit ab8ccdf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
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]))
4 changes: 2 additions & 2 deletions ext/mysql2/result.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,11 @@ 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];

fprintf(stderr, "field.charsetnr: %d\n", field.charsetnr);
fprintf(stderr, "enc_name: %s\n", enc_name);

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 ab8ccdf

Please sign in to comment.