ruby-changes:50582
From: nobu <ko1@a...>
Date: Mon, 12 Mar 2018 22:04:35 +0900 (JST)
Subject: [ruby-changes:50582] nobu:r62728 (trunk): eval_error.c: fix underflow
nobu 2018-03-12 22:04:28 +0900 (Mon, 12 Mar 2018) New Revision: 62728 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=62728 Log: eval_error.c: fix underflow * eval_error.c (print_errinfo): get rid of negative string length. [ruby-core:86086] [Bug #14598] Modified files: trunk/eval_error.c trunk/test/ruby/test_exception.rb Index: eval_error.c =================================================================== --- eval_error.c (revision 62727) +++ eval_error.c (revision 62728) @@ -129,15 +129,13 @@ print_errinfo(const VALUE eclass, const https://github.com/ruby/ruby/blob/trunk/eval_error.c#L129 } else { const char *tail = 0; - long len = elen; if (emesg == Qundef && highlight) write_warn(str, bold); if (RSTRING_PTR(epath)[0] == '#') epath = 0; if ((tail = memchr(einfo, '\n', elen)) != 0) { - len = tail - einfo; + write_warn2(str, einfo, tail - einfo); tail++; /* skip newline */ - write_warn2(str, einfo, len); } else { write_warn_str(str, emesg); @@ -159,7 +157,7 @@ print_errinfo(const VALUE eclass, const https://github.com/ruby/ruby/blob/trunk/eval_error.c#L157 if (einfo[elen-1] == '\n') --elen; write_warn(str, bold); } - write_warn2(str, tail, elen - len - 1); + if (tail < einfo+elen) write_warn2(str, tail, einfo+elen-tail); } if (tail ? (highlight || einfo[elen-1] != '\n') : !epath) { if (highlight) write_warn(str, reset); Index: test/ruby/test_exception.rb =================================================================== --- test/ruby/test_exception.rb (revision 62727) +++ test/ruby/test_exception.rb (revision 62728) @@ -1254,5 +1254,13 @@ $stderr = $stdout; raise "\x82\xa0"') do https://github.com/ruby/ruby/blob/trunk/test/ruby/test_exception.rb#L1254 _, err2, status1 = EnvUtil.invoke_ruby(['-e', "#{test_method}; begin; foo; end"], '', true, true) assert_equal(err2, out1) + + if $stderr.tty? + e = RuntimeError.new("a\n") + message = assert_nothing_raised(ArgumentError, proc {e.pretty_inspect}) do + e.full_message + end + assert_operator(message, :end_with?, "\n") + end end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/