Skip to content

Commit 75c4e9b

Browse files
committed
Named the magic number for regexp option buffer size
In `rb_enc_reg_error_desc`, no longer kcode option is added.
1 parent 1f09c43 commit 75c4e9b

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

re.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,10 @@ char_to_option(int c)
311311
return val;
312312
}
313313

314+
static const int OPTBUF_SIZE = 4;
315+
314316
static char *
315-
option_to_str(char str[4], int options)
317+
option_to_str(char str[OPTBUF_SIZE], int options)
316318
{
317319
char *p = str;
318320
if (options & ONIG_OPTION_MULTILINE) *p++ = 'm';
@@ -462,7 +464,7 @@ rb_reg_desc(const char *s, long len, VALUE re)
462464
rb_reg_expr_str(str, s, len, enc, resenc, '/');
463465
rb_str_buf_cat2(str, "/");
464466
if (re) {
465-
char opts[4];
467+
char opts[OPTBUF_SIZE];
466468
rb_reg_check(re);
467469
if (*option_to_str(opts, RREGEXP_PTR(re)->options))
468470
rb_str_buf_cat2(str, opts);
@@ -554,7 +556,7 @@ rb_reg_str_with_term(VALUE re, int term)
554556
long len;
555557
const UChar* ptr;
556558
VALUE str = rb_str_buf_new2("(?");
557-
char optbuf[5];
559+
char optbuf[OPTBUF_SIZE + 1]; /* for '-' */
558560
rb_encoding *enc = rb_enc_get(re);
559561

560562
rb_reg_check(re);
@@ -668,7 +670,7 @@ rb_reg_raise(const char *s, long len, const char *err, VALUE re)
668670
static VALUE
669671
rb_enc_reg_error_desc(const char *s, long len, rb_encoding *enc, int options, const char *err)
670672
{
671-
char opts[6];
673+
char opts[OPTBUF_SIZE + 1]; /* for '/' */
672674
VALUE desc = rb_str_buf_new2(err);
673675
rb_encoding *resenc = rb_default_internal_encoding();
674676
if (resenc == NULL) resenc = rb_default_external_encoding();

0 commit comments

Comments
 (0)