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

ruby-changes:56542

From: Yusuke <ko1@a...>
Date: Mon, 15 Jul 2019 12:01:41 +0900 (JST)
Subject: [ruby-changes:56542] Yusuke Endoh: 76bad330aa (master): encoding.c (enc_table_expand): prefer xrealloc to realloc

https://git.ruby-lang.org/ruby.git/commit/?id=76bad330aa

From 76bad330aae4ee867585dda3e547e5db740fc0f3 Mon Sep 17 00:00:00 2001
From: Yusuke Endoh <mame@r...>
Date: Mon, 15 Jul 2019 12:00:12 +0900
Subject: encoding.c (enc_table_expand): prefer xrealloc to realloc

And raise an exception when failed to register an encoding

diff --git a/encoding.c b/encoding.c
index f4606ee..ff5e488 100644
--- a/encoding.c
+++ b/encoding.c
@@ -268,8 +268,7 @@ enc_table_expand(int newsize) https://github.com/ruby/ruby/blob/trunk/encoding.c#L268
 
     if (enc_table.size >= newsize) return newsize;
     newsize = (newsize + 7) / 8 * 8;
-    ent = realloc(enc_table.list, sizeof(*enc_table.list) * newsize);
-    if (!ent) return -1;
+    ent = xrealloc(enc_table.list, sizeof(*enc_table.list) * newsize);
     memset(ent + enc_table.size, 0, sizeof(*ent)*(newsize - enc_table.size));
     enc_table.list = ent;
     enc_table.size = newsize;
@@ -443,6 +442,9 @@ enc_replicate_with_index(const char *name, rb_encoding *origenc, int idx) https://github.com/ruby/ruby/blob/trunk/encoding.c#L442
 	set_base_encoding(idx, origenc);
 	set_encoding_const(name, rb_enc_from_index(idx));
     }
+    else {
+        rb_raise(rb_eArgError, "failed to replicate encoding");
+    }
     return idx;
 }
 
-- 
cgit v0.10.2


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

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