summaryrefslogtreecommitdiff
path: root/re.c
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2020-08-28 19:29:16 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2020-08-28 19:29:16 +0900
commit75c4e9b72eca22b087c8c2d6d8a950922545aa00 (patch)
tree790da6bdf043b546904fdb2eaab3b7d62b2b92ba /re.c
parent1f09c4362806e3ce8a7b15e0effc3abb7f53411d (diff)
Named the magic number for regexp option buffer size
In `rb_enc_reg_error_desc`, no longer kcode option is added.
Diffstat (limited to 're.c')
-rw-r--r--re.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/re.c b/re.c
index a967c93452..d0dbfaaa29 100644
--- a/re.c
+++ b/re.c
@@ -311,8 +311,10 @@ char_to_option(int c)
return val;
}
+static const int OPTBUF_SIZE = 4;
+
static char *
-option_to_str(char str[4], int options)
+option_to_str(char str[OPTBUF_SIZE], int options)
{
char *p = str;
if (options & ONIG_OPTION_MULTILINE) *p++ = 'm';
@@ -462,7 +464,7 @@ rb_reg_desc(const char *s, long len, VALUE re)
rb_reg_expr_str(str, s, len, enc, resenc, '/');
rb_str_buf_cat2(str, "/");
if (re) {
- char opts[4];
+ char opts[OPTBUF_SIZE];
rb_reg_check(re);
if (*option_to_str(opts, RREGEXP_PTR(re)->options))
rb_str_buf_cat2(str, opts);
@@ -554,7 +556,7 @@ rb_reg_str_with_term(VALUE re, int term)
long len;
const UChar* ptr;
VALUE str = rb_str_buf_new2("(?");
- char optbuf[5];
+ char optbuf[OPTBUF_SIZE + 1]; /* for '-' */
rb_encoding *enc = rb_enc_get(re);
rb_reg_check(re);
@@ -668,7 +670,7 @@ rb_reg_raise(const char *s, long len, const char *err, VALUE re)
static VALUE
rb_enc_reg_error_desc(const char *s, long len, rb_encoding *enc, int options, const char *err)
{
- char opts[6];
+ char opts[OPTBUF_SIZE + 1]; /* for '/' */
VALUE desc = rb_str_buf_new2(err);
rb_encoding *resenc = rb_default_internal_encoding();
if (resenc == NULL) resenc = rb_default_external_encoding();