ruby-changes:49409
From: nobu <ko1@a...>
Date: Sun, 31 Dec 2017 22:01:59 +0900 (JST)
Subject: [ruby-changes:49409] nobu:r61525 (trunk): error.c: negative uplevel
nobu 2017-12-31 22:01:55 +0900 (Sun, 31 Dec 2017) New Revision: 61525 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=61525 Log: error.c: negative uplevel * error.c (rb_warn_m): negative uplevel is not allowed. [ruby-core:84568] [Bug #14262] Modified files: trunk/error.c trunk/test/ruby/test_exception.rb Index: error.c =================================================================== --- error.c (revision 61524) +++ error.c (revision 61525) @@ -342,7 +342,11 @@ rb_warn_m(int argc, VALUE *argv, VALUE e https://github.com/ruby/ruby/blob/trunk/error.c#L342 uplevel = Qnil; } else if (!NIL_P(uplevel)) { - uplevel = LONG2NUM((long)NUM2ULONG(uplevel) + 1); + long lev = NUM2LONG(uplevel); + if (lev < 0) { + rb_raise(rb_eArgError, "negative level (%ld)", lev); + } + uplevel = LONG2NUM(lev + 1); uplevel = rb_vm_thread_backtrace_locations(1, &uplevel, GET_THREAD()->self); if (!NIL_P(uplevel)) { uplevel = rb_ary_entry(uplevel, 0); Index: test/ruby/test_exception.rb =================================================================== --- test/ruby/test_exception.rb (revision 61524) +++ test/ruby/test_exception.rb (revision 61525) @@ -1007,6 +1007,7 @@ $stderr = $stdout; raise "\x82\xa0"') do https://github.com/ruby/ruby/blob/trunk/test/ruby/test_exception.rb#L1007 def test_kernel_warn_uplevel warning = capture_warning_warn {warn("test warning", uplevel: 0)} assert_equal("#{__FILE__}:#{__LINE__-1}: warning: test warning\n", warning[0]) + assert_raise(ArgumentError) {warn("test warning", uplevel: -1)} end def test_warning_warn_invalid_argument -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/