[前][次][番号順一覧][スレッド一覧]

ruby-changes:62740

From: Nobuyoshi <ko1@a...>
Date: Fri, 28 Aug 2020 19:30:48 +0900 (JST)
Subject: [ruby-changes:62740] 75c4e9b72e (master): Named the magic number for regexp option buffer size

https://git.ruby-lang.org/ruby.git/commit/?id=75c4e9b72e

From 75c4e9b72eca22b087c8c2d6d8a950922545aa00 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Fri, 28 Aug 2020 19:29:16 +0900
Subject: Named the magic number for regexp option buffer size

In `rb_enc_reg_error_desc`, no longer kcode option is added.

diff --git a/re.c b/re.c
index a967c93..d0dbfaa 100644
--- a/re.c
+++ b/re.c
@@ -311,8 +311,10 @@ char_to_option(int c) https://github.com/ruby/ruby/blob/trunk/re.c#L311
     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) https://github.com/ruby/ruby/blob/trunk/re.c#L464
     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) https://github.com/ruby/ruby/blob/trunk/re.c#L556
     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) https://github.com/ruby/ruby/blob/trunk/re.c#L670
 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();
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]