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

ruby-changes:58669

From: Koichi <ko1@a...>
Date: Sat, 9 Nov 2019 10:04:25 +0900 (JST)
Subject: [ruby-changes:58669] 21f7cca2c6 (master): initialize kw special local var.

https://git.ruby-lang.org/ruby.git/commit/?id=21f7cca2c6

From 21f7cca2c6394aaaec9189a7cb08a9ad8a2196e3 Mon Sep 17 00:00:00 2001
From: Koichi Sasada <ko1@a...>
Date: Sat, 9 Nov 2019 09:59:32 +0900
Subject: initialize kw special local var.

A method which has keyword parameters has an implicit local variable
to specify which keywords are (un)specified.

vm_call_iseq_setup_kwparm_nokwarg() is special function to invoke
a ISeq method without any keyword arguments. However, it should
also initialize the special local var. Without this initialization,
the implicit lvar can points a freed (T_NONE) object.

diff --git a/vm_insnhelper.c b/vm_insnhelper.c
index 890cbf6..8378fc3 100644
--- a/vm_insnhelper.c
+++ b/vm_insnhelper.c
@@ -2073,9 +2073,12 @@ vm_call_iseq_setup_kwparm_nokwarg(rb_execution_context_t *ec, rb_control_frame_t https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L2073
     VALUE * const argv = cfp->sp - calling->argc;
     VALUE * const klocals = argv + kw_param->bits_start - kw_param->num;
 
-    for (int i=0; i<kw_param->num; i++) {
+    int i;
+    for (i=0; i<kw_param->num; i++) {
         klocals[i] = kw_param->default_values[i];
     }
+    klocals[i] = INT2FIX(0); // kw specify flag
+
     /* NOTE: don't need to setup (clear) unspecified bits
              because no code check it.
              klocals[kw_param->num] = INT2FIX(0); */
-- 
cgit v0.10.2


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

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