diff --git a/src/builtin.cpp b/src/builtin.cpp index 91276b9b7..085b278da 100644 --- a/src/builtin.cpp +++ b/src/builtin.cpp @@ -144,14 +144,14 @@ int parse_help_only_cmd_opts(struct help_only_cmd_opts_t &opts, int *optind, int /// /// Process and print help for the specified builtin or function. void builtin_print_help(parser_t &parser, const io_streams_t &streams, const wchar_t *name, - wcstring *error_message) { + const wcstring &error_message) { // This won't ever work if no_exec is set. if (no_exec()) return; const wcstring name_esc = escape_string(name); wcstring cmd = format_string(L"__fish_print_help %ls ", name_esc.c_str()); io_chain_t ios; - if (error_message) { - cmd.append(escape_string(*error_message)); + if (!error_message.empty()) { + cmd.append(escape_string(error_message)); // If it's an error, redirect the output of __fish_print_help to stderr ios.push_back(std::make_shared(STDOUT_FILENO, STDERR_FILENO)); } @@ -268,7 +268,7 @@ static maybe_t builtin_break_continue(parser_t &parser, io_streams_t &strea if (argc != 1) { wcstring error_message = format_string(BUILTIN_ERR_UNKNOWN, argv[0], argv[1]); - builtin_print_help(parser, streams, argv[0], &error_message); + builtin_print_help(parser, streams, argv[0], error_message); return STATUS_INVALID_ARGS; } @@ -284,7 +284,7 @@ static maybe_t builtin_break_continue(parser_t &parser, io_streams_t &strea } if (!has_loop) { wcstring error_message = format_string(_(L"%ls: Not inside of loop\n"), argv[0]); - builtin_print_help(parser, streams, argv[0], &error_message); + builtin_print_help(parser, streams, argv[0], error_message); return STATUS_CMD_ERROR; } diff --git a/src/builtin.h b/src/builtin.h index 5668cf059..3e0685683 100644 --- a/src/builtin.h +++ b/src/builtin.h @@ -88,7 +88,7 @@ const wchar_t *builtin_get_desc(const wcstring &name); wcstring builtin_help_get(parser_t &parser, const wchar_t *cmd); void builtin_print_help(parser_t &parser, const io_streams_t &streams, const wchar_t *name, - wcstring *error_message = nullptr); + const wcstring &error_message = {}); int builtin_count_args(const wchar_t *const *argv); void builtin_unknown_option(parser_t &parser, io_streams_t &streams, const wchar_t *cmd, diff --git a/src/builtins/bg.cpp b/src/builtins/bg.cpp index 87be5ce60..77a93a947 100644 --- a/src/builtins/bg.cpp +++ b/src/builtins/bg.cpp @@ -27,7 +27,7 @@ static int send_to_bg(parser_t &parser, io_streams_t &streams, job_t *j) { wcstring error_message = format_string( _(L"%ls: Can't put job %d, '%ls' to background because it is not under job control\n"), L"bg", j->job_id(), j->command_wcstr()); - builtin_print_help(parser, streams, L"bg", &error_message); + builtin_print_help(parser, streams, L"bg", error_message); return STATUS_CMD_ERROR; }