From c7a5cc2c3098ea74343a0dbab36b3a65bc7a4144 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Mon, 21 Dec 2020 21:46:10 +0900 Subject: [PATCH] Replaced magic numbers tr table --- string.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/string.c b/string.c index dfb38e4e98..3dab48c701 100644 --- a/string.c +++ b/string.c @@ -7580,13 +7580,14 @@ rb_str_tr(VALUE str, VALUE src, VALUE repl) return str; } -#define TR_TABLE_SIZE 257 +#define TR_TABLE_MAX (UCHAR_MAX+1) +#define TR_TABLE_SIZE (TR_TABLE_MAX+1) static void tr_setup_table(VALUE str, char stable[TR_TABLE_SIZE], int first, VALUE *tablep, VALUE *ctablep, rb_encoding *enc) { const unsigned int errc = -1; - char buf[256]; + char buf[TR_TABLE_MAX]; struct tr tr; unsigned int c; VALUE table = 0, ptable = 0; @@ -7600,26 +7601,26 @@ tr_setup_table(VALUE str, char stable[TR_TABLE_SIZE], int first, tr.p += l; } if (first) { - for (i=0; i<256; i++) { + for (i=0; i