Skip to content

Commit

Permalink
Allow -1 as the value of --backtrace-limit option
Browse files Browse the repository at this point in the history
-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.
  • Loading branch information
tomstuart authored and nobu committed Jul 15, 2023
1 parent 125b446 commit de68e24
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ruby.c
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion test/ruby/test_rubyoptions.rb
Expand Up @@ -74,7 +74,7 @@ def test_option_variables
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/,
Expand Down

0 comments on commit de68e24

Please sign in to comment.