From de68e240c7a1ded3049ee23d8bf2db5a15f4f39b Mon Sep 17 00:00:00 2001 From: Tom Stuart Date: Sat, 1 Jul 2023 15:19:01 +0100 Subject: [PATCH] Allow -1 as the value of `--backtrace-limit` option MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -1 is a legitimate backtrace limit — in fact, it’s the default — so it should be possible to provide it with the `--backtrace-limit` option. --- ruby.c | 2 +- test/ruby/test_rubyoptions.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ruby.c b/ruby.c index 92ea37b4f6..30e0e68360 100644 --- a/ruby.c +++ b/ruby.c @@ -1449,7 +1449,7 @@ proc_long_options(ruby_cmdline_options_t *opt, const char *s, long argc, char ** else if (is_option_with_arg("backtrace-limit", Qfalse, Qtrue)) { char *e; long n = strtol(s, &e, 10); - if (errno == ERANGE || n < 0 || *e) rb_raise(rb_eRuntimeError, "wrong limit for backtrace length"); + if (errno == ERANGE || n < -1 || *e) rb_raise(rb_eRuntimeError, "wrong limit for backtrace length"); opt->backtrace_length_limit = (int)n; } else { diff --git a/test/ruby/test_rubyoptions.rb b/test/ruby/test_rubyoptions.rb index 5a90258926..5fdcf128cf 100644 --- a/test/ruby/test_rubyoptions.rb +++ b/test/ruby/test_rubyoptions.rb @@ -74,7 +74,7 @@ class TestRubyOptions < Test::Unit::TestCase def test_backtrace_limit assert_in_out_err(%w(--backtrace-limit), "", [], /missing argument for --backtrace-limit/) assert_in_out_err(%w(--backtrace-limit= 1), "", [], /missing argument for --backtrace-limit/) - assert_in_out_err(%w(--backtrace-limit=-1), "", [], /wrong limit for backtrace length/) + assert_in_out_err(%w(--backtrace-limit=-2), "", [], /wrong limit for backtrace length/) code = 'def f(n);n > 0 ? f(n-1) : raise;end;f(5)' assert_in_out_err(%w(--backtrace-limit=1), code, [], [/.*unhandled exception\n/, /^\tfrom .*\n/,