From 1055ff321c137a0d9263d7a03918167a9df969d4 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Mon, 18 Nov 2019 18:34:50 -0800 Subject: [PATCH] [clang-tidy] Replace NULL with nullptr Found with modernize-use-nullptr Signed-off-by: Rosen Penev --- src/builtin.cpp | 27 +++++----- src/builtin_argparse.cpp | 16 +++--- src/builtin_bg.cpp | 2 +- src/builtin_bind.cpp | 36 ++++++------- src/builtin_block.cpp | 18 +++---- src/builtin_builtin.cpp | 10 ++-- src/builtin_command.cpp | 12 ++--- src/builtin_commandline.cpp | 45 +++++++++-------- src/builtin_complete.cpp | 51 +++++++++---------- src/builtin_contains.cpp | 7 +-- src/builtin_disown.cpp | 2 +- src/builtin_echo.cpp | 6 +-- src/builtin_exit.cpp | 6 +-- src/builtin_function.cpp | 27 +++++----- src/builtin_functions.cpp | 30 +++++------ src/builtin_history.cpp | 38 +++++++------- src/builtin_jobs.cpp | 18 +++---- src/builtin_math.cpp | 18 +++---- src/builtin_printf.cpp | 2 +- src/builtin_pwd.cpp | 6 +-- src/builtin_read.cpp | 44 ++++++++-------- src/builtin_return.cpp | 6 +-- src/builtin_set.cpp | 18 +++---- src/builtin_set_color.cpp | 32 ++++++------ src/builtin_status.cpp | 40 +++++++-------- src/builtin_string.cpp | 97 ++++++++++++++++++------------------ src/builtin_test.cpp | 32 ++++++------ src/builtin_ulimit.cpp | 34 ++++++------- src/builtin_wait.cpp | 6 +-- src/common.cpp | 43 ++++++++-------- src/common.h | 22 ++++---- src/complete.cpp | 22 ++++---- src/env.cpp | 10 ++-- src/env.h | 2 +- src/env_dispatch.cpp | 12 ++--- src/env_universal_common.cpp | 22 ++++---- src/env_universal_common.h | 2 +- src/event.h | 3 +- src/exec.cpp | 12 ++--- src/expand.cpp | 8 +-- src/expand.h | 4 +- src/fallback.cpp | 8 +-- src/fish.cpp | 43 ++++++++-------- src/fish_indent.cpp | 28 +++++------ src/fish_key_reader.cpp | 23 +++++---- src/function.cpp | 2 +- src/highlight.cpp | 18 +++---- src/history.cpp | 14 +++--- src/history_file.cpp | 22 ++++---- src/input.cpp | 4 +- src/input.h | 2 +- src/input_common.cpp | 4 +- src/intern.cpp | 2 +- src/io.cpp | 4 +- src/iothread.cpp | 6 +-- src/lru.h | 10 ++-- src/output.cpp | 4 +- src/pager.cpp | 2 +- src/parse_constants.h | 4 +- src/parse_execution.cpp | 16 +++--- src/parse_productions.cpp | 8 +-- src/parse_tree.cpp | 26 +++++----- src/parse_util.cpp | 46 ++++++++--------- src/parse_util.h | 6 +-- src/parser.cpp | 42 ++++++++-------- src/postfork.cpp | 2 +- src/proc.cpp | 8 +-- src/proc.h | 4 +- src/reader.cpp | 48 +++++++++--------- src/sanity.cpp | 2 +- src/screen.cpp | 10 ++-- src/signal.cpp | 32 ++++++------ src/tinyexpr.cpp | 16 +++--- src/tnode.cpp | 14 +++--- src/utf8.cpp | 20 ++++---- src/util.cpp | 2 +- src/wgetopt.cpp | 26 +++++----- src/wildcard.cpp | 34 ++++++------- src/wutil.cpp | 12 ++--- src/wutil.h | 9 ++-- 80 files changed, 721 insertions(+), 710 deletions(-) diff --git a/src/builtin.cpp b/src/builtin.cpp index eb65c84ab..f01c0a4dc 100644 --- a/src/builtin.cpp +++ b/src/builtin.cpp @@ -89,11 +89,11 @@ bool builtin_data_t::operator<(const builtin_data_t *other) const { /// Counts the number of arguments in the specified null-terminated array int builtin_count_args(const wchar_t *const *argv) { int argc; - for (argc = 1; argv[argc] != NULL;) { + for (argc = 1; argv[argc] != nullptr;) { argc++; } - assert(argv[argc] == NULL); + assert(argv[argc] == nullptr); return argc; } @@ -101,11 +101,11 @@ int builtin_count_args(const wchar_t *const *argv) { /// to stderr. Used by the builtin commands. void builtin_wperror(const wchar_t *s, io_streams_t &streams) { char *err = std::strerror(errno); - if (s != NULL) { + if (s != nullptr) { streams.err.append(s); streams.err.append(L": "); } - if (err != NULL) { + if (err != nullptr) { const wcstring werr = str2wcstring(err); streams.err.append(werr); streams.err.push_back(L'\n'); @@ -113,15 +113,15 @@ void builtin_wperror(const wchar_t *s, io_streams_t &streams) { } static const wchar_t *const short_options = L"+:h"; -static const struct woption long_options[] = {{L"help", no_argument, NULL, 'h'}, - {NULL, 0, NULL, 0}}; +static const struct woption long_options[] = {{L"help", no_argument, nullptr, 'h'}, + {nullptr, 0, nullptr, 0}}; int parse_help_only_cmd_opts(struct help_only_cmd_opts_t &opts, int *optind, int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) { wchar_t *cmd = argv[0]; int opt; wgetopter_t w; - while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) { + while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, nullptr)) != -1) { switch (opt) { //!OCLINT(too few branches) case 'h': { opts.print_help = true; @@ -283,7 +283,7 @@ static int builtin_break_continue(parser_t &parser, io_streams_t &streams, wchar /// Implementation of the builtin breakpoint command, used to launch the interactive debugger. static int builtin_breakpoint(parser_t &parser, io_streams_t &streams, wchar_t **argv) { wchar_t *cmd = argv[0]; - if (argv[1] != NULL) { + if (argv[1] != nullptr) { streams.err.append_format(BUILTIN_ERR_ARG_COUNT1, cmd, 0, builtin_count_args(argv) - 1); return STATUS_INVALID_ARGS; } @@ -310,7 +310,7 @@ static int builtin_breakpoint(parser_t &parser, io_streams_t &streams, wchar_t * int builtin_true(parser_t &parser, io_streams_t &streams, wchar_t **argv) { UNUSED(parser); UNUSED(streams); - if (argv[1] != NULL) { + if (argv[1] != nullptr) { streams.err.append_format(BUILTIN_ERR_ARG_COUNT1, argv[0], 0, builtin_count_args(argv) - 1); return STATUS_INVALID_ARGS; } @@ -320,7 +320,7 @@ int builtin_true(parser_t &parser, io_streams_t &streams, wchar_t **argv) { int builtin_false(parser_t &parser, io_streams_t &streams, wchar_t **argv) { UNUSED(parser); UNUSED(streams); - if (argv[1] != NULL) { + if (argv[1] != nullptr) { streams.err.append_format(BUILTIN_ERR_ARG_COUNT1, argv[0], 0, builtin_count_args(argv) - 1); return STATUS_INVALID_ARGS; } @@ -408,7 +408,7 @@ static const builtin_data_t *builtin_lookup(const wcstring &name) { if (found != array_end && name == found->name) { return found; } - return NULL; + return nullptr; } /// Initialize builtin data. @@ -433,7 +433,8 @@ static bool cmd_needs_help(const wchar_t *cmd) { return contains(help_builtins, proc_status_t builtin_run(parser_t &parser, int job_pgid, wchar_t **argv, io_streams_t &streams) { UNUSED(parser); UNUSED(streams); - if (argv == NULL || argv[0] == NULL) return proc_status_t::from_exit_code(STATUS_INVALID_ARGS); + if (argv == nullptr || argv[0] == nullptr) + return proc_status_t::from_exit_code(STATUS_INVALID_ARGS); // We can be handed a keyword by the parser as if it was a command. This happens when the user // follows the keyword by `-h` or `--help`. Since it isn't really a builtin command we need to @@ -471,7 +472,7 @@ wcstring_list_t builtin_get_names() { /// Insert all builtin names into list. void builtin_get_names(std::vector *list) { - assert(list != NULL); + assert(list != nullptr); list->reserve(list->size() + BUILTIN_COUNT); for (size_t i = 0; i < BUILTIN_COUNT; i++) { append_completion(list, builtin_datas[i].name); diff --git a/src/builtin_argparse.cpp b/src/builtin_argparse.cpp index 113988106..c99ee7128 100644 --- a/src/builtin_argparse.cpp +++ b/src/builtin_argparse.cpp @@ -60,10 +60,10 @@ struct argparse_cmd_opts_t { static const wchar_t *const short_options = L"+:hn:six:N:X:"; static const struct woption long_options[] = { - {L"stop-nonopt", no_argument, NULL, 's'}, {L"ignore-unknown", no_argument, NULL, 'i'}, - {L"name", required_argument, NULL, 'n'}, {L"exclusive", required_argument, NULL, 'x'}, - {L"help", no_argument, NULL, 'h'}, {L"min-args", required_argument, NULL, 'N'}, - {L"max-args", required_argument, NULL, 'X'}, {NULL, 0, NULL, 0}}; + {L"stop-nonopt", no_argument, nullptr, 's'}, {L"ignore-unknown", no_argument, nullptr, 'i'}, + {L"name", required_argument, nullptr, 'n'}, {L"exclusive", required_argument, nullptr, 'x'}, + {L"help", no_argument, nullptr, 'h'}, {L"min-args", required_argument, nullptr, 'N'}, + {L"max-args", required_argument, nullptr, 'X'}, {nullptr, 0, nullptr, 0}}; // Check if any pair of mutually exclusive options was seen. Note that since every option must have // a short name we only need to check those. @@ -343,7 +343,7 @@ static int parse_cmd_opts(argparse_cmd_opts_t &opts, int *optind, //!OCLINT(hig wchar_t *cmd = argv[0]; int opt; wgetopter_t w; - while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) { + while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, nullptr)) != -1) { switch (opt) { case 'n': { opts.name = w.woptarg; @@ -440,10 +440,10 @@ static void populate_option_strings(const argparse_cmd_opts_t &opts, wcstring *s if (!opt_spec->long_flag.empty()) { long_options->push_back( - {opt_spec->long_flag.c_str(), arg_type, NULL, opt_spec->short_flag}); + {opt_spec->long_flag.c_str(), arg_type, nullptr, opt_spec->short_flag}); } } - long_options->push_back({NULL, 0, NULL, 0}); + long_options->push_back({nullptr, 0, nullptr, 0}); } static int validate_arg(parser_t &parser, const argparse_cmd_opts_t &opts, option_spec_t *opt_spec, @@ -501,7 +501,7 @@ static int validate_and_store_implicit_int(parser_t &parser, const argparse_cmd_ opt_spec->vals.clear(); opt_spec->vals.push_back(wcstring(val)); opt_spec->num_seen++; - w.nextchar = NULL; + w.nextchar = nullptr; return STATUS_CMD_OK; } diff --git a/src/builtin_bg.cpp b/src/builtin_bg.cpp index 96e42d8b7..4858e0c8e 100644 --- a/src/builtin_bg.cpp +++ b/src/builtin_bg.cpp @@ -18,7 +18,7 @@ /// Helper function for builtin_bg(). static int send_to_bg(parser_t &parser, io_streams_t &streams, job_t *j) { - assert(j != NULL); + assert(j != nullptr); if (!j->wants_job_control()) { wcstring error_message = format_string( _(L"%ls: Can't put job %d, '%ls' to background because it is not under job control\n"), diff --git a/src/builtin_bind.cpp b/src/builtin_bind.cpp index 7b478c88c..e4b715d91 100644 --- a/src/builtin_bind.cpp +++ b/src/builtin_bind.cpp @@ -211,7 +211,7 @@ bool builtin_bind_t::erase(wchar_t **seq, bool all, const wchar_t *mode, bool us } bool res = false; - if (mode == NULL) mode = DEFAULT_BIND_MODE; //!OCLINT(parameter reassignment) + if (mode == nullptr) mode = DEFAULT_BIND_MODE; //!OCLINT(parameter reassignment) while (*seq) { if (use_terminfo) { @@ -253,10 +253,10 @@ bool builtin_bind_t::insert(int optind, int argc, wchar_t **argv, io_streams_t & // We don't overload this with user and def because we want them to be grouped. // First the presets, then the users (because of scrolling). if (opts->preset) { - list(opts->bind_mode_given ? opts->bind_mode : NULL, false, streams); + list(opts->bind_mode_given ? opts->bind_mode : nullptr, false, streams); } if (opts->user) { - list(opts->bind_mode_given ? opts->bind_mode : NULL, true, streams); + list(opts->bind_mode_given ? opts->bind_mode : nullptr, true, streams); } } else if (arg_count == 1) { wcstring seq; @@ -318,23 +318,23 @@ int parse_cmd_opts(bind_cmd_opts_t &opts, int *optind, //!OCLINT(high ncss meth int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) { wchar_t *cmd = argv[0]; static const wchar_t *const short_options = L":aehkKfM:Lm:s"; - static const struct woption long_options[] = {{L"all", no_argument, NULL, 'a'}, - {L"erase", no_argument, NULL, 'e'}, - {L"function-names", no_argument, NULL, 'f'}, - {L"help", no_argument, NULL, 'h'}, - {L"key", no_argument, NULL, 'k'}, - {L"key-names", no_argument, NULL, 'K'}, - {L"list-modes", no_argument, NULL, 'L'}, - {L"mode", required_argument, NULL, 'M'}, - {L"preset", no_argument, NULL, 'p'}, - {L"sets-mode", required_argument, NULL, 'm'}, - {L"silent", no_argument, NULL, 's'}, - {L"user", no_argument, NULL, 'u'}, - {NULL, 0, NULL, 0}}; + static const struct woption long_options[] = {{L"all", no_argument, nullptr, 'a'}, + {L"erase", no_argument, nullptr, 'e'}, + {L"function-names", no_argument, nullptr, 'f'}, + {L"help", no_argument, nullptr, 'h'}, + {L"key", no_argument, nullptr, 'k'}, + {L"key-names", no_argument, nullptr, 'K'}, + {L"list-modes", no_argument, nullptr, 'L'}, + {L"mode", required_argument, nullptr, 'M'}, + {L"preset", no_argument, nullptr, 'p'}, + {L"sets-mode", required_argument, nullptr, 'm'}, + {L"silent", no_argument, nullptr, 's'}, + {L"user", no_argument, nullptr, 'u'}, + {nullptr, 0, nullptr, 0}}; int opt; wgetopter_t w; - while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) { + while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, nullptr)) != -1) { switch (opt) { case L'a': { opts.all = true; @@ -438,7 +438,7 @@ int builtin_bind_t::builtin_bind(parser_t &parser, io_streams_t &streams, wchar_ if (!opts.have_preset && !opts.have_user) opts.user = true; switch (opts.mode) { case BIND_ERASE: { - const wchar_t *bind_mode = opts.bind_mode_given ? opts.bind_mode : NULL; + const wchar_t *bind_mode = opts.bind_mode_given ? opts.bind_mode : nullptr; // If we get both, we erase both. if (opts.user) { if (erase(&argv[optind], opts.all, bind_mode, opts.use_terminfo, /* user */ true, diff --git a/src/builtin_block.cpp b/src/builtin_block.cpp index 2a44992f1..d97ceecf2 100644 --- a/src/builtin_block.cpp +++ b/src/builtin_block.cpp @@ -25,15 +25,15 @@ static int parse_cmd_opts(block_cmd_opts_t &opts, int *optind, //!OCLINT(high n int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) { wchar_t *cmd = argv[0]; static const wchar_t *const short_options = L":eghl"; - static const struct woption long_options[] = {{L"erase", no_argument, NULL, 'e'}, - {L"local", no_argument, NULL, 'l'}, - {L"global", no_argument, NULL, 'g'}, - {L"help", no_argument, NULL, 'h'}, - {NULL, 0, NULL, 0}}; + static const struct woption long_options[] = {{L"erase", no_argument, nullptr, 'e'}, + {L"local", no_argument, nullptr, 'l'}, + {L"global", no_argument, nullptr, 'g'}, + {L"help", no_argument, nullptr, 'h'}, + {nullptr, 0, nullptr, 0}}; int opt; wgetopter_t w; - while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) { + while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, nullptr)) != -1) { switch (opt) { case 'h': { opts.print_help = true; @@ -108,16 +108,16 @@ int builtin_block(parser_t &parser, io_streams_t &streams, wchar_t **argv) { case LOCAL: { // If this is the outermost block, then we're global if (block_idx + 1 >= parser.block_count()) { - block = NULL; + block = nullptr; } break; } case GLOBAL: { - block = NULL; + block = nullptr; break; } case UNSET: { - while (block != NULL && block->type() != FUNCTION_CALL && + while (block != nullptr && block->type() != FUNCTION_CALL && block->type() != FUNCTION_CALL_NO_SHADOW) { // Set it in function scope block = parser.block_at_index(++block_idx); diff --git a/src/builtin_builtin.cpp b/src/builtin_builtin.cpp index 1ce2c04a8..eca1b4bd2 100644 --- a/src/builtin_builtin.cpp +++ b/src/builtin_builtin.cpp @@ -20,17 +20,17 @@ struct builtin_cmd_opts_t { bool query = false; }; static const wchar_t *const short_options = L":hnq"; -static const struct woption long_options[] = {{L"help", no_argument, NULL, 'h'}, - {L"names", no_argument, NULL, 'n'}, - {L"query", no_argument, NULL, 'q'}, - {NULL, 0, NULL, 0}}; +static const struct woption long_options[] = {{L"help", no_argument, nullptr, 'h'}, + {L"names", no_argument, nullptr, 'n'}, + {L"query", no_argument, nullptr, 'q'}, + {nullptr, 0, nullptr, 0}}; static int parse_cmd_opts(builtin_cmd_opts_t &opts, int *optind, int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) { wchar_t *cmd = argv[0]; int opt; wgetopter_t w; - while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) { + while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, nullptr)) != -1) { switch (opt) { case 'h': { opts.print_help = true; diff --git a/src/builtin_command.cpp b/src/builtin_command.cpp index 396850528..91cad034d 100644 --- a/src/builtin_command.cpp +++ b/src/builtin_command.cpp @@ -23,18 +23,18 @@ struct command_cmd_opts_t { bool all_paths = false; }; static const wchar_t *const short_options = L":ahqsv"; -static const struct woption long_options[] = {{L"help", no_argument, NULL, 'h'}, - {L"all", no_argument, NULL, 'a'}, - {L"quiet", no_argument, NULL, 'q'}, - {L"search", no_argument, NULL, 's'}, - {NULL, 0, NULL, 0}}; +static const struct woption long_options[] = {{L"help", no_argument, nullptr, 'h'}, + {L"all", no_argument, nullptr, 'a'}, + {L"quiet", no_argument, nullptr, 'q'}, + {L"search", no_argument, nullptr, 's'}, + {nullptr, 0, nullptr, 0}}; static int parse_cmd_opts(command_cmd_opts_t &opts, int *optind, int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) { wchar_t *cmd = argv[0]; int opt; wgetopter_t w; - while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) { + while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, nullptr)) != -1) { switch (opt) { case 'a': { opts.all_paths = true; diff --git a/src/builtin_commandline.cpp b/src/builtin_commandline.cpp index c342bf229..f91db88b0 100644 --- a/src/builtin_commandline.cpp +++ b/src/builtin_commandline.cpp @@ -125,7 +125,7 @@ static void write_part(const wchar_t *begin, const wchar_t *end, int cut_at_curs int builtin_commandline(parser_t &parser, io_streams_t &streams, wchar_t **argv) { // Pointer to what the commandline builtin considers to be the current contents of the command // line buffer. - const wchar_t *current_buffer = 0; + const wchar_t *current_buffer = nullptr; // What the commandline builtin considers to be the current cursor position. auto current_cursor_pos = static_cast(-1); @@ -146,7 +146,7 @@ int builtin_commandline(parser_t &parser, io_streams_t &streams, wchar_t **argv) int line_mode = 0; int search_mode = 0; int paging_mode = 0; - const wchar_t *begin = NULL, *end = NULL; + const wchar_t *begin = nullptr, *end = nullptr; const auto &ld = parser.libdata(); wcstring transient_commandline; @@ -173,28 +173,28 @@ int builtin_commandline(parser_t &parser, io_streams_t &streams, wchar_t **argv) } static const wchar_t *const short_options = L":abijpctforhI:CLSsP"; - static const struct woption long_options[] = {{L"append", no_argument, NULL, 'a'}, - {L"insert", no_argument, NULL, 'i'}, - {L"replace", no_argument, NULL, 'r'}, - {L"current-buffer", no_argument, NULL, 'b'}, - {L"current-job", no_argument, NULL, 'j'}, - {L"current-process", no_argument, NULL, 'p'}, - {L"current-selection", no_argument, NULL, 's'}, - {L"current-token", no_argument, NULL, 't'}, - {L"cut-at-cursor", no_argument, NULL, 'c'}, - {L"function", no_argument, NULL, 'f'}, - {L"tokenize", no_argument, NULL, 'o'}, - {L"help", no_argument, NULL, 'h'}, - {L"input", required_argument, NULL, 'I'}, - {L"cursor", no_argument, NULL, 'C'}, - {L"line", no_argument, NULL, 'L'}, - {L"search-mode", no_argument, NULL, 'S'}, - {L"paging-mode", no_argument, NULL, 'P'}, - {NULL, 0, NULL, 0}}; + static const struct woption long_options[] = {{L"append", no_argument, nullptr, 'a'}, + {L"insert", no_argument, nullptr, 'i'}, + {L"replace", no_argument, nullptr, 'r'}, + {L"current-buffer", no_argument, nullptr, 'b'}, + {L"current-job", no_argument, nullptr, 'j'}, + {L"current-process", no_argument, nullptr, 'p'}, + {L"current-selection", no_argument, nullptr, 's'}, + {L"current-token", no_argument, nullptr, 't'}, + {L"cut-at-cursor", no_argument, nullptr, 'c'}, + {L"function", no_argument, nullptr, 'f'}, + {L"tokenize", no_argument, nullptr, 'o'}, + {L"help", no_argument, nullptr, 'h'}, + {L"input", required_argument, nullptr, 'I'}, + {L"cursor", no_argument, nullptr, 'C'}, + {L"line", no_argument, nullptr, 'L'}, + {L"search-mode", no_argument, nullptr, 'S'}, + {L"paging-mode", no_argument, nullptr, 'P'}, + {nullptr, 0, nullptr, 0}}; int opt; wgetopter_t w; - while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) { + while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, nullptr)) != -1) { switch (opt) { case L'a': { append_mode = APPEND_MODE; @@ -408,7 +408,8 @@ int builtin_commandline(parser_t &parser, io_streams_t &streams, wchar_t **argv) break; } case TOKEN_MODE: { - parse_util_token_extent(current_buffer, current_cursor_pos, &begin, &end, 0, 0); + parse_util_token_extent(current_buffer, current_cursor_pos, &begin, &end, nullptr, + nullptr); break; } default: { diff --git a/src/builtin_complete.cpp b/src/builtin_complete.cpp index 8355486e0..28fb3d4f6 100644 --- a/src/builtin_complete.cpp +++ b/src/builtin_complete.cpp @@ -128,30 +128,31 @@ int builtin_complete(parser_t &parser, io_streams_t &streams, wchar_t **argv) { bool preserve_order = false; static const wchar_t *const short_options = L":a:c:p:s:l:o:d:fFrxeuAn:C::w:hk"; - static const struct woption long_options[] = {{L"exclusive", no_argument, NULL, 'x'}, - {L"no-files", no_argument, NULL, 'f'}, - {L"force-files", no_argument, NULL, 'F'}, - {L"require-parameter", no_argument, NULL, 'r'}, - {L"path", required_argument, NULL, 'p'}, - {L"command", required_argument, NULL, 'c'}, - {L"short-option", required_argument, NULL, 's'}, - {L"long-option", required_argument, NULL, 'l'}, - {L"old-option", required_argument, NULL, 'o'}, - {L"description", required_argument, NULL, 'd'}, - {L"arguments", required_argument, NULL, 'a'}, - {L"erase", no_argument, NULL, 'e'}, - {L"unauthoritative", no_argument, NULL, 'u'}, - {L"authoritative", no_argument, NULL, 'A'}, - {L"condition", required_argument, NULL, 'n'}, - {L"wraps", required_argument, NULL, 'w'}, - {L"do-complete", optional_argument, NULL, 'C'}, - {L"help", no_argument, NULL, 'h'}, - {L"keep-order", no_argument, NULL, 'k'}, - {NULL, 0, NULL, 0}}; + static const struct woption long_options[] = { + {L"exclusive", no_argument, nullptr, 'x'}, + {L"no-files", no_argument, nullptr, 'f'}, + {L"force-files", no_argument, nullptr, 'F'}, + {L"require-parameter", no_argument, nullptr, 'r'}, + {L"path", required_argument, nullptr, 'p'}, + {L"command", required_argument, nullptr, 'c'}, + {L"short-option", required_argument, nullptr, 's'}, + {L"long-option", required_argument, nullptr, 'l'}, + {L"old-option", required_argument, nullptr, 'o'}, + {L"description", required_argument, nullptr, 'd'}, + {L"arguments", required_argument, nullptr, 'a'}, + {L"erase", no_argument, nullptr, 'e'}, + {L"unauthoritative", no_argument, nullptr, 'u'}, + {L"authoritative", no_argument, nullptr, 'A'}, + {L"condition", required_argument, nullptr, 'n'}, + {L"wraps", required_argument, nullptr, 'w'}, + {L"do-complete", optional_argument, nullptr, 'C'}, + {L"help", no_argument, nullptr, 'h'}, + {L"keep-order", no_argument, nullptr, 'k'}, + {nullptr, 0, nullptr, 0}}; int opt; wgetopter_t w; - while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) { + while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, nullptr)) != -1) { switch (opt) { case 'x': { result_mode.no_files = true; @@ -241,7 +242,7 @@ int builtin_complete(parser_t &parser, io_streams_t &streams, wchar_t **argv) { } case 'C': { do_complete = true; - have_do_complete_param = w.woptarg != NULL; + have_do_complete_param = w.woptarg != nullptr; if (have_do_complete_param) do_complete_param = w.woptarg; break; } @@ -317,7 +318,7 @@ int builtin_complete(parser_t &parser, io_streams_t &streams, wchar_t **argv) { if (!have_do_complete_param) { // No argument given, try to use the current commandline. const wchar_t *cmd = reader_get_buffer(); - if (cmd == NULL) { + if (cmd == nullptr) { // This corresponds to using 'complete -C' in non-interactive mode. // See #2361 . builtin_missing_argument(parser, streams, cmd, argv[w.woptind - 1]); @@ -327,8 +328,8 @@ int builtin_complete(parser_t &parser, io_streams_t &streams, wchar_t **argv) { } const wchar_t *token; - parse_util_token_extent(do_complete_param.c_str(), do_complete_param.size(), &token, 0, 0, - 0); + parse_util_token_extent(do_complete_param.c_str(), do_complete_param.size(), &token, + nullptr, nullptr, nullptr); // Create a scoped transient command line, so that builtin_commandline will see our // argument, not the reader buffer. diff --git a/src/builtin_contains.cpp b/src/builtin_contains.cpp index c98c0bb1a..a9e018859 100644 --- a/src/builtin_contains.cpp +++ b/src/builtin_contains.cpp @@ -19,15 +19,16 @@ struct contains_cmd_opts_t { bool print_index = false; }; static const wchar_t *const short_options = L"+:hi"; -static const struct woption long_options[] = { - {L"help", no_argument, NULL, 'h'}, {L"index", no_argument, NULL, 'i'}, {NULL, 0, NULL, 0}}; +static const struct woption long_options[] = {{L"help", no_argument, nullptr, 'h'}, + {L"index", no_argument, nullptr, 'i'}, + {nullptr, 0, nullptr, 0}}; static int parse_cmd_opts(contains_cmd_opts_t &opts, int *optind, int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) { wchar_t *cmd = argv[0]; int opt; wgetopter_t w; - while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) { + while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, nullptr)) != -1) { switch (opt) { case 'h': { opts.print_help = true; diff --git a/src/builtin_disown.cpp b/src/builtin_disown.cpp index 8b90830fa..bdf2f4373 100644 --- a/src/builtin_disown.cpp +++ b/src/builtin_disown.cpp @@ -55,7 +55,7 @@ int builtin_disown(parser_t &parser, io_streams_t &streams, wchar_t **argv) { return STATUS_CMD_OK; } - if (argv[1] == 0) { + if (argv[1] == nullptr) { // Select last constructed job (ie first job in the job queue) that is possible to disown. // Stopped jobs can be disowned (they will be continued). // Foreground jobs can be disowned. diff --git a/src/builtin_echo.cpp b/src/builtin_echo.cpp index 45165d0f8..d2bd798f1 100644 --- a/src/builtin_echo.cpp +++ b/src/builtin_echo.cpp @@ -19,7 +19,7 @@ struct echo_cmd_opts_t { bool interpret_special_chars = false; }; static const wchar_t *const short_options = L"+:Eens"; -static const struct woption *const long_options = NULL; +static const struct woption *const long_options = nullptr; static int parse_cmd_opts(echo_cmd_opts_t &opts, int *optind, int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) { @@ -28,7 +28,7 @@ static int parse_cmd_opts(echo_cmd_opts_t &opts, int *optind, int argc, wchar_t wchar_t *cmd = argv[0]; int opt; wgetopter_t w; - while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) { + while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, nullptr)) != -1) { switch (opt) { case 'n': { opts.print_newline = false; @@ -194,7 +194,7 @@ int builtin_echo(parser_t &parser, io_streams_t &streams, wchar_t **argv) { bool continue_output = true; const wchar_t *const *args_to_echo = argv + optind; - for (size_t idx = 0; continue_output && args_to_echo[idx] != NULL; idx++) { + for (size_t idx = 0; continue_output && args_to_echo[idx] != nullptr; idx++) { if (opts.print_spaces && idx > 0) { streams.out.push_back(' '); } diff --git a/src/builtin_exit.cpp b/src/builtin_exit.cpp index 3b77cd521..920107116 100644 --- a/src/builtin_exit.cpp +++ b/src/builtin_exit.cpp @@ -20,8 +20,8 @@ struct exit_cmd_opts_t { bool print_help = false; }; static const wchar_t *const short_options = L":h"; -static const struct woption long_options[] = {{L"help", no_argument, NULL, 'h'}, - {NULL, 0, NULL, 0}}; +static const struct woption long_options[] = {{L"help", no_argument, nullptr, 'h'}, + {nullptr, 0, nullptr, 0}}; static int parse_cmd_opts(exit_cmd_opts_t &opts, int *optind, //!OCLINT(high ncss method) int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) { @@ -30,7 +30,7 @@ static int parse_cmd_opts(exit_cmd_opts_t &opts, int *optind, //!OCLINT(high nc wchar_t *cmd = argv[0]; int opt; wgetopter_t w; - while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) { + while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, nullptr)) != -1) { switch (opt) { //!OCLINT(too few branches) case 'h': { opts.print_help = true; diff --git a/src/builtin_function.cpp b/src/builtin_function.cpp index 9df7ca366..b1a6655f5 100644 --- a/src/builtin_function.cpp +++ b/src/builtin_function.cpp @@ -39,18 +39,19 @@ struct function_cmd_opts_t { // This command is atypical in using the "-" (RETURN_IN_ORDER) option for flag parsing. // This is needed due to the semantics of the -a/--argument-names flag. static const wchar_t *const short_options = L"-:a:d:e:hj:p:s:v:w:SV:"; -static const struct woption long_options[] = {{L"description", required_argument, NULL, 'd'}, - {L"on-signal", required_argument, NULL, 's'}, - {L"on-job-exit", required_argument, NULL, 'j'}, - {L"on-process-exit", required_argument, NULL, 'p'}, - {L"on-variable", required_argument, NULL, 'v'}, - {L"on-event", required_argument, NULL, 'e'}, - {L"wraps", required_argument, NULL, 'w'}, - {L"help", no_argument, NULL, 'h'}, - {L"argument-names", required_argument, NULL, 'a'}, - {L"no-scope-shadowing", no_argument, NULL, 'S'}, - {L"inherit-variable", required_argument, NULL, 'V'}, - {NULL, 0, NULL, 0}}; +static const struct woption long_options[] = { + {L"description", required_argument, nullptr, 'd'}, + {L"on-signal", required_argument, nullptr, 's'}, + {L"on-job-exit", required_argument, nullptr, 'j'}, + {L"on-process-exit", required_argument, nullptr, 'p'}, + {L"on-variable", required_argument, nullptr, 'v'}, + {L"on-event", required_argument, nullptr, 'e'}, + {L"wraps", required_argument, nullptr, 'w'}, + {L"help", no_argument, nullptr, 'h'}, + {L"argument-names", required_argument, nullptr, 'a'}, + {L"no-scope-shadowing", no_argument, nullptr, 'S'}, + {L"inherit-variable", required_argument, nullptr, 'V'}, + {nullptr, 0, nullptr, 0}}; static int parse_cmd_opts(function_cmd_opts_t &opts, int *optind, //!OCLINT(high ncss method) int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) { @@ -58,7 +59,7 @@ static int parse_cmd_opts(function_cmd_opts_t &opts, int *optind, //!OCLINT(hig int opt; wgetopter_t w; bool handling_named_arguments = false; - while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) { + while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, nullptr)) != -1) { if (opt != 'a' && opt != 1) handling_named_arguments = false; switch (opt) { case 1: { diff --git a/src/builtin_functions.cpp b/src/builtin_functions.cpp index bf2001e38..04d684871 100644 --- a/src/builtin_functions.cpp +++ b/src/builtin_functions.cpp @@ -39,29 +39,29 @@ struct functions_cmd_opts_t { bool report_metadata = false; bool verbose = false; bool handlers = false; - wchar_t *handlers_type = NULL; - wchar_t *description = NULL; + wchar_t *handlers_type = nullptr; + wchar_t *description = nullptr; }; static const wchar_t *const short_options = L":HDacd:ehnqv"; -static const struct woption long_options[] = {{L"erase", no_argument, NULL, 'e'}, - {L"description", required_argument, NULL, 'd'}, - {L"names", no_argument, NULL, 'n'}, - {L"all", no_argument, NULL, 'a'}, - {L"help", no_argument, NULL, 'h'}, - {L"query", no_argument, NULL, 'q'}, - {L"copy", no_argument, NULL, 'c'}, - {L"details", no_argument, NULL, 'D'}, - {L"verbose", no_argument, NULL, 'v'}, - {L"handlers", no_argument, NULL, 'H'}, - {L"handlers-type", required_argument, NULL, 't'}, - {NULL, 0, NULL, 0}}; +static const struct woption long_options[] = {{L"erase", no_argument, nullptr, 'e'}, + {L"description", required_argument, nullptr, 'd'}, + {L"names", no_argument, nullptr, 'n'}, + {L"all", no_argument, nullptr, 'a'}, + {L"help", no_argument, nullptr, 'h'}, + {L"query", no_argument, nullptr, 'q'}, + {L"copy", no_argument, nullptr, 'c'}, + {L"details", no_argument, nullptr, 'D'}, + {L"verbose", no_argument, nullptr, 'v'}, + {L"handlers", no_argument, nullptr, 'H'}, + {L"handlers-type", required_argument, nullptr, 't'}, + {nullptr, 0, nullptr, 0}}; static int parse_cmd_opts(functions_cmd_opts_t &opts, int *optind, //!OCLINT(high ncss method) int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) { wchar_t *cmd = argv[0]; int opt; wgetopter_t w; - while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) { + while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, nullptr)) != -1) { switch (opt) { case 'v': { opts.verbose = true; diff --git a/src/builtin_history.cpp b/src/builtin_history.cpp index 991dbf288..4df5e30f4 100644 --- a/src/builtin_history.cpp +++ b/src/builtin_history.cpp @@ -25,12 +25,12 @@ enum hist_cmd_t { HIST_SEARCH = 1, HIST_DELETE, HIST_CLEAR, HIST_MERGE, HIST_SAV // Must be sorted by string, not enum or random. static const enum_map hist_enum_map[] = { {HIST_CLEAR, L"clear"}, {HIST_DELETE, L"delete"}, {HIST_MERGE, L"merge"}, - {HIST_SAVE, L"save"}, {HIST_SEARCH, L"search"}, {HIST_UNDEF, NULL}}; + {HIST_SAVE, L"save"}, {HIST_SEARCH, L"search"}, {HIST_UNDEF, nullptr}}; struct history_cmd_opts_t { hist_cmd_t hist_cmd = HIST_UNDEF; history_search_type_t search_type = static_cast(-1); - const wchar_t *show_time_format = NULL; + const wchar_t *show_time_format = nullptr; size_t max_items = SIZE_MAX; bool print_help = false; bool history_search_type_defined = false; @@ -44,21 +44,21 @@ struct history_cmd_opts_t { /// supported at least until fish 3.0 and possibly longer to avoid breaking everyones /// config.fish and other scripts. static const wchar_t *const short_options = L":CRcehmn:pt::z"; -static const struct woption long_options[] = {{L"prefix", no_argument, NULL, 'p'}, - {L"contains", no_argument, NULL, 'c'}, - {L"help", no_argument, NULL, 'h'}, - {L"show-time", optional_argument, NULL, 't'}, - {L"exact", no_argument, NULL, 'e'}, - {L"max", required_argument, NULL, 'n'}, - {L"null", no_argument, NULL, 'z'}, - {L"case-sensitive", no_argument, NULL, 'C'}, - {L"delete", no_argument, NULL, 1}, - {L"search", no_argument, NULL, 2}, - {L"save", no_argument, NULL, 3}, - {L"clear", no_argument, NULL, 4}, - {L"merge", no_argument, NULL, 5}, - {L"reverse", no_argument, NULL, 'R'}, - {NULL, 0, NULL, 0}}; +static const struct woption long_options[] = {{L"prefix", no_argument, nullptr, 'p'}, + {L"contains", no_argument, nullptr, 'c'}, + {L"help", no_argument, nullptr, 'h'}, + {L"show-time", optional_argument, nullptr, 't'}, + {L"exact", no_argument, nullptr, 'e'}, + {L"max", required_argument, nullptr, 'n'}, + {L"null", no_argument, nullptr, 'z'}, + {L"case-sensitive", no_argument, nullptr, 'C'}, + {L"delete", no_argument, nullptr, 1}, + {L"search", no_argument, nullptr, 2}, + {L"save", no_argument, nullptr, 3}, + {L"clear", no_argument, nullptr, 4}, + {L"merge", no_argument, nullptr, 5}, + {L"reverse", no_argument, nullptr, 'R'}, + {nullptr, 0, nullptr, 0}}; /// Remember the history subcommand and disallow selecting more than one history subcommand. static bool set_hist_cmd(wchar_t *const cmd, hist_cmd_t *hist_cmd, hist_cmd_t sub_cmd, @@ -99,7 +99,7 @@ static int parse_cmd_opts(history_cmd_opts_t &opts, int *optind, //!OCLINT(high wchar_t *cmd = argv[0]; int opt; wgetopter_t w; - while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) { + while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, nullptr)) != -1) { switch (opt) { case 1: { if (!set_hist_cmd(cmd, &opts.hist_cmd, HIST_DELETE, streams)) { @@ -186,7 +186,7 @@ static int parse_cmd_opts(history_cmd_opts_t &opts, int *optind, //!OCLINT(high builtin_unknown_option(parser, streams, cmd, argv[w.woptind - 1]); return STATUS_INVALID_ARGS; } - w.nextchar = NULL; + w.nextchar = nullptr; break; } default: { diff --git a/src/builtin_jobs.cpp b/src/builtin_jobs.cpp index 0a7b12e38..3b2530ae7 100644 --- a/src/builtin_jobs.cpp +++ b/src/builtin_jobs.cpp @@ -33,7 +33,7 @@ static int cpu_use(const job_t *j) { for (const process_ptr_t &p : j->processes) { struct timeval t; int jiffies; - gettimeofday(&t, 0); + gettimeofday(&t, nullptr); jiffies = proc_get_jiffies(p.get()); double t1 = 1000000.0 * p->last_time.tv_sec + p->last_time.tv_usec; @@ -119,17 +119,17 @@ int builtin_jobs(parser_t &parser, io_streams_t &streams, wchar_t **argv) { int print_last = 0; static const wchar_t *const short_options = L":cghlpq"; - static const struct woption long_options[] = {{L"command", no_argument, NULL, 'c'}, - {L"group", no_argument, NULL, 'g'}, - {L"help", no_argument, NULL, 'h'}, - {L"last", no_argument, NULL, 'l'}, - {L"pid", no_argument, NULL, 'p'}, - {L"quiet", no_argument, NULL, 'q'}, - {nullptr, 0, NULL, 0}}; + static const struct woption long_options[] = {{L"command", no_argument, nullptr, 'c'}, + {L"group", no_argument, nullptr, 'g'}, + {L"help", no_argument, nullptr, 'h'}, + {L"last", no_argument, nullptr, 'l'}, + {L"pid", no_argument, nullptr, 'p'}, + {L"quiet", no_argument, nullptr, 'q'}, + {nullptr, 0, nullptr, 0}}; int opt; wgetopter_t w; - while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) { + while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, nullptr)) != -1) { switch (opt) { case 'p': { mode = JOBS_PRINT_PID; diff --git a/src/builtin_math.cpp b/src/builtin_math.cpp index 451410471..6ae67677b 100644 --- a/src/builtin_math.cpp +++ b/src/builtin_math.cpp @@ -35,16 +35,16 @@ struct math_cmd_opts_t { // This command is atypical in using the "+" (REQUIRE_ORDER) option for flag parsing. // This is needed because of the minus, `-`, operator in math expressions. static const wchar_t *const short_options = L"+:hs:"; -static const struct woption long_options[] = {{L"scale", required_argument, NULL, 's'}, - {L"help", no_argument, NULL, 'h'}, - {NULL, 0, NULL, 0}}; +static const struct woption long_options[] = {{L"scale", required_argument, nullptr, 's'}, + {L"help", no_argument, nullptr, 'h'}, + {nullptr, 0, nullptr, 0}}; static int parse_cmd_opts(math_cmd_opts_t &opts, int *optind, //!OCLINT(high ncss method) int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) { const wchar_t *cmd = L"math"; int opt; wgetopter_t w; - while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) { + while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, nullptr)) != -1) { switch (opt) { case 's': { // "max" is the special value that tells us to pick the maximum scale. @@ -97,10 +97,10 @@ static const wchar_t *math_get_arg_stdin(wcstring *storage, const io_streams_t & char ch = '\0'; long rc = read_blocked(streams.stdin_fd, &ch, 1); - if (rc < 0) return NULL; // failure + if (rc < 0) return nullptr; // failure if (rc == 0) { // EOF - if (arg.empty()) return NULL; + if (arg.empty()) return nullptr; break; } @@ -115,7 +115,7 @@ static const wchar_t *math_get_arg_stdin(wcstring *storage, const io_streams_t & /// Return the next argument from argv. static const wchar_t *math_get_arg_argv(int *argidx, wchar_t **argv) { - return argv && argv[*argidx] ? argv[(*argidx)++] : NULL; + return argv && argv[*argidx] ? argv[(*argidx)++] : nullptr; } /// Get the arguments from argv or stdin based on the execution context. This mimics how builtin @@ -196,7 +196,7 @@ static int evaluate_expression(const wchar_t *cmd, parser_t &parser, io_streams_ // Switch locale while computing stuff. // This means that the "." is always the radix character, // so numbers work the same across locales. - char *saved_locale = strdup(setlocale(LC_NUMERIC, NULL)); + char *saved_locale = strdup(setlocale(LC_NUMERIC, nullptr)); setlocale(LC_NUMERIC, "C"); double v = te_interp(narrow_str.c_str(), &error); @@ -205,7 +205,7 @@ static int evaluate_expression(const wchar_t *cmd, parser_t &parser, io_streams_ // TODO: Really, this should be done in tinyexpr // (e.g. infinite is the result of "x / 0"), // but that's much more work. - const char *error_message = NULL; + const char *error_message = nullptr; if (std::isinf(v)) { error_message = "Result is infinite"; } else if (std::isnan(v)) { diff --git a/src/builtin_printf.cpp b/src/builtin_printf.cpp index d6401fc9a..e8a208b12 100644 --- a/src/builtin_printf.cpp +++ b/src/builtin_printf.cpp @@ -304,7 +304,7 @@ static T string_to_scalar_type(const wchar_t *s, builtin_printf_state_t *state) wchar_t ch = *++s; val = ch; } else { - wchar_t *end = NULL; + wchar_t *end = nullptr; errno = 0; val = raw_string_to_scalar_type(s, &end); state->verify_numeric(s, end, errno); diff --git a/src/builtin_pwd.cpp b/src/builtin_pwd.cpp index 8c0c7a71a..e81e9f512 100644 --- a/src/builtin_pwd.cpp +++ b/src/builtin_pwd.cpp @@ -15,8 +15,8 @@ /// The pwd builtin. Respect -P to resolve symbolic links. Respect -L to not do that (the default). static const wchar_t *const short_options = L"LPh"; -static const struct woption long_options[] = {{L"help", no_argument, NULL, 'h'}, - {NULL, 0, NULL, 0}}; +static const struct woption long_options[] = {{L"help", no_argument, nullptr, 'h'}, + {nullptr, 0, nullptr, 0}}; int builtin_pwd(parser_t &parser, io_streams_t &streams, wchar_t **argv) { UNUSED(parser); const wchar_t *cmd = argv[0]; @@ -24,7 +24,7 @@ int builtin_pwd(parser_t &parser, io_streams_t &streams, wchar_t **argv) { bool resolve_symlinks = false; wgetopter_t w; int opt; - while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) { + while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, nullptr)) != -1) { switch (opt) { case 'L': resolve_symlinks = false; diff --git a/src/builtin_read.cpp b/src/builtin_read.cpp index 90d03f8cc..d743b3357 100644 --- a/src/builtin_read.cpp +++ b/src/builtin_read.cpp @@ -38,8 +38,8 @@ struct read_cmd_opts_t { bool print_help = false; int place = ENV_USER; wcstring prompt_cmd; - const wchar_t *prompt = NULL; - const wchar_t *prompt_str = NULL; + const wchar_t *prompt = nullptr; + const wchar_t *prompt_str = nullptr; const wchar_t *right_prompt = L""; const wchar_t *commandline = L""; // If a delimiter was given. Used to distinguish between the default @@ -56,32 +56,32 @@ struct read_cmd_opts_t { }; static const wchar_t *const short_options = L":ac:d:ghiLlm:n:p:sSuxzP:UR:LB"; -static const struct woption long_options[] = {{L"array", no_argument, NULL, 'a'}, - {L"command", required_argument, NULL, 'c'}, - {L"delimiter", required_argument, NULL, 'd'}, - {L"export", no_argument, NULL, 'x'}, - {L"global", no_argument, NULL, 'g'}, - {L"help", no_argument, NULL, 'h'}, - {L"line", no_argument, NULL, 'L'}, - {L"list", no_argument, NULL, 'a'}, - {L"local", no_argument, NULL, 'l'}, - {L"nchars", required_argument, NULL, 'n'}, - {L"null", no_argument, NULL, 'z'}, - {L"prompt", required_argument, NULL, 'p'}, - {L"prompt-str", required_argument, NULL, 'P'}, - {L"right-prompt", required_argument, NULL, 'R'}, - {L"shell", no_argument, NULL, 'S'}, - {L"silent", no_argument, NULL, 's'}, - {L"unexport", no_argument, NULL, 'u'}, - {L"universal", no_argument, NULL, 'U'}, - {NULL, 0, NULL, 0}}; +static const struct woption long_options[] = {{L"array", no_argument, nullptr, 'a'}, + {L"command", required_argument, nullptr, 'c'}, + {L"delimiter", required_argument, nullptr, 'd'}, + {L"export", no_argument, nullptr, 'x'}, + {L"global", no_argument, nullptr, 'g'}, + {L"help", no_argument, nullptr, 'h'}, + {L"line", no_argument, nullptr, 'L'}, + {L"list", no_argument, nullptr, 'a'}, + {L"local", no_argument, nullptr, 'l'}, + {L"nchars", required_argument, nullptr, 'n'}, + {L"null", no_argument, nullptr, 'z'}, + {L"prompt", required_argument, nullptr, 'p'}, + {L"prompt-str", required_argument, nullptr, 'P'}, + {L"right-prompt", required_argument, nullptr, 'R'}, + {L"shell", no_argument, nullptr, 'S'}, + {L"silent", no_argument, nullptr, 's'}, + {L"unexport", no_argument, nullptr, 'u'}, + {L"universal", no_argument, nullptr, 'U'}, + {nullptr, 0, nullptr, 0}}; static int parse_cmd_opts(read_cmd_opts_t &opts, int *optind, //!OCLINT(high ncss method) int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) { wchar_t *cmd = argv[0]; int opt; wgetopter_t w; - while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) { + while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, nullptr)) != -1) { switch (opt) { case 'a': { opts.array = true; diff --git a/src/builtin_return.cpp b/src/builtin_return.cpp index 7663efb75..579ca5835 100644 --- a/src/builtin_return.cpp +++ b/src/builtin_return.cpp @@ -19,8 +19,8 @@ struct return_cmd_opts_t { bool print_help = false; }; static const wchar_t *const short_options = L":h"; -static const struct woption long_options[] = {{L"help", no_argument, NULL, 'h'}, - {NULL, 0, NULL, 0}}; +static const struct woption long_options[] = {{L"help", no_argument, nullptr, 'h'}, + {nullptr, 0, nullptr, 0}}; static int parse_cmd_opts(return_cmd_opts_t &opts, int *optind, //!OCLINT(high ncss method) int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) { @@ -29,7 +29,7 @@ static int parse_cmd_opts(return_cmd_opts_t &opts, int *optind, //!OCLINT(high wchar_t *cmd = argv[0]; int opt; wgetopter_t w; - while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) { + while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, nullptr)) != -1) { switch (opt) { //!OCLINT(too few branches) case 'h': { opts.print_help = true; diff --git a/src/builtin_set.cpp b/src/builtin_set.cpp index 4246a04bb..1798d2fc3 100644 --- a/src/builtin_set.cpp +++ b/src/builtin_set.cpp @@ -58,14 +58,14 @@ enum { // we stop scanning for flags when the first non-flag argument is seen. static const wchar_t *const short_options = L"+:LSUaeghlnpqux"; static const struct woption long_options[] = { - {L"export", no_argument, NULL, 'x'}, {L"global", no_argument, NULL, 'g'}, - {L"local", no_argument, NULL, 'l'}, {L"erase", no_argument, NULL, 'e'}, - {L"names", no_argument, NULL, 'n'}, {L"unexport", no_argument, NULL, 'u'}, - {L"universal", no_argument, NULL, 'U'}, {L"long", no_argument, NULL, 'L'}, - {L"query", no_argument, NULL, 'q'}, {L"show", no_argument, NULL, 'S'}, - {L"append", no_argument, NULL, 'a'}, {L"prepend", no_argument, NULL, 'p'}, - {L"path", no_argument, NULL, opt_path}, {L"unpath", no_argument, NULL, opt_unpath}, - {L"help", no_argument, NULL, 'h'}, {NULL, 0, NULL, 0}}; + {L"export", no_argument, nullptr, 'x'}, {L"global", no_argument, nullptr, 'g'}, + {L"local", no_argument, nullptr, 'l'}, {L"erase", no_argument, nullptr, 'e'}, + {L"names", no_argument, nullptr, 'n'}, {L"unexport", no_argument, nullptr, 'u'}, + {L"universal", no_argument, nullptr, 'U'}, {L"long", no_argument, nullptr, 'L'}, + {L"query", no_argument, nullptr, 'q'}, {L"show", no_argument, nullptr, 'S'}, + {L"append", no_argument, nullptr, 'a'}, {L"prepend", no_argument, nullptr, 'p'}, + {L"path", no_argument, nullptr, opt_path}, {L"unpath", no_argument, nullptr, opt_unpath}, + {L"help", no_argument, nullptr, 'h'}, {nullptr, 0, nullptr, 0}}; // Hint for invalid path operation with a colon. #define BUILTIN_SET_PATH_ERROR _(L"%ls: Warning: $%ls entry \"%ls\" is not valid (%s)\n") @@ -86,7 +86,7 @@ static int parse_cmd_opts(set_cmd_opts_t &opts, int *optind, //!OCLINT(high ncs int opt; wgetopter_t w; - while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) { + while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, nullptr)) != -1) { switch (opt) { case 'a': { opts.append = true; diff --git a/src/builtin_set_color.cpp b/src/builtin_set_color.cpp index ecd78fb88..78788928c 100644 --- a/src/builtin_set_color.cpp +++ b/src/builtin_set_color.cpp @@ -49,16 +49,16 @@ static void print_colors(io_streams_t &streams) { } static const wchar_t *const short_options = L":b:hvoidrcu"; -static const struct woption long_options[] = {{L"background", required_argument, NULL, 'b'}, - {L"help", no_argument, NULL, 'h'}, - {L"bold", no_argument, NULL, 'o'}, - {L"underline", no_argument, NULL, 'u'}, - {L"italics", no_argument, NULL, 'i'}, - {L"dim", no_argument, NULL, 'd'}, - {L"reverse", no_argument, NULL, 'r'}, - {L"version", no_argument, NULL, 'v'}, - {L"print-colors", no_argument, NULL, 'c'}, - {NULL, 0, NULL, 0}}; +static const struct woption long_options[] = {{L"background", required_argument, nullptr, 'b'}, + {L"help", no_argument, nullptr, 'h'}, + {L"bold", no_argument, nullptr, 'o'}, + {L"underline", no_argument, nullptr, 'u'}, + {L"italics", no_argument, nullptr, 'i'}, + {L"dim", no_argument, nullptr, 'd'}, + {L"reverse", no_argument, nullptr, 'r'}, + {L"version", no_argument, nullptr, 'v'}, + {L"print-colors", no_argument, nullptr, 'c'}, + {nullptr, 0, nullptr, 0}}; #if __APPLE__ static char sitm_esc[] = "\x1B[3m"; @@ -96,13 +96,13 @@ int builtin_set_color(parser_t &parser, io_streams_t &streams, wchar_t **argv) { return EXIT_FAILURE; } - const wchar_t *bgcolor = NULL; + const wchar_t *bgcolor = nullptr; bool bold = false, underline = false, italics = false, dim = false, reverse = false; // Parse options to obtain the requested operation and the modifiers. int opt; wgetopter_t w; - while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) { + while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, nullptr)) != -1) { switch (opt) { case 'b': { bgcolor = w.woptarg; @@ -161,7 +161,7 @@ int builtin_set_color(parser_t &parser, io_streams_t &streams, wchar_t **argv) { fgcolors.push_back(fg); } - if (fgcolors.empty() && bgcolor == NULL && !bold && !underline && !italics && !dim && + if (fgcolors.empty() && bgcolor == nullptr && !bold && !underline && !italics && !dim && !reverse) { streams.err.append_format(_(L"%ls: Expected an argument\n"), argv[0]); return STATUS_INVALID_ARGS; @@ -180,7 +180,7 @@ int builtin_set_color(parser_t &parser, io_streams_t &streams, wchar_t **argv) { // Test if we have at least basic support for setting fonts, colors and related bits - otherwise // just give up... - if (cur_term == NULL || !exit_attribute_mode) { + if (cur_term == nullptr || !exit_attribute_mode) { return STATUS_CMD_ERROR; } outputter_t outp; @@ -207,7 +207,7 @@ int builtin_set_color(parser_t &parser, io_streams_t &streams, wchar_t **argv) { writembs_nofail(outp, enter_standout_mode); } - if (bgcolor != NULL && bg.is_normal()) { + if (bgcolor != nullptr && bg.is_normal()) { writembs_nofail(outp, tparm((char *)exit_attribute_mode)); } @@ -224,7 +224,7 @@ int builtin_set_color(parser_t &parser, io_streams_t &streams, wchar_t **argv) { } } - if (bgcolor != NULL && !bg.is_normal() && !bg.is_reset()) { + if (bgcolor != nullptr && !bg.is_normal() && !bg.is_reset()) { outp.write_color(bg, false /* not is_fg */); } diff --git a/src/builtin_status.cpp b/src/builtin_status.cpp index fd97f5e0f..2fcbce962 100644 --- a/src/builtin_status.cpp +++ b/src/builtin_status.cpp @@ -61,7 +61,7 @@ const enum_map status_enum_map[] = { {STATUS_STACK_TRACE, L"print-stack-trace"}, {STATUS_STACK_TRACE, L"stack-trace"}, {STATUS_TEST_FEATURE, L"test-feature"}, - {STATUS_UNDEF, NULL}}; + {STATUS_UNDEF, nullptr}}; #define status_enum_map_len (sizeof status_enum_map / sizeof *status_enum_map) #define CHECK_FOR_UNEXPECTED_STATUS_ARGS(status_cmd) \ @@ -103,24 +103,24 @@ struct status_cmd_opts_t { /// scripts. static const wchar_t *const short_options = L":L:cbilfnhj:t"; static const struct woption long_options[] = { - {L"help", no_argument, NULL, 'h'}, - {L"current-filename", no_argument, NULL, 'f'}, - {L"current-line-number", no_argument, NULL, 'n'}, - {L"filename", no_argument, NULL, 'f'}, - {L"fish-path", no_argument, NULL, STATUS_FISH_PATH}, - {L"is-block", no_argument, NULL, 'b'}, - {L"is-command-substitution", no_argument, NULL, 'c'}, - {L"is-full-job-control", no_argument, NULL, STATUS_IS_FULL_JOB_CTRL}, - {L"is-interactive", no_argument, NULL, 'i'}, - {L"is-interactive-job-control", no_argument, NULL, STATUS_IS_INTERACTIVE_JOB_CTRL}, - {L"is-login", no_argument, NULL, 'l'}, - {L"is-no-job-control", no_argument, NULL, STATUS_IS_NO_JOB_CTRL}, - {L"job-control", required_argument, NULL, 'j'}, - {L"level", required_argument, NULL, 'L'}, - {L"line", no_argument, NULL, 'n'}, - {L"line-number", no_argument, NULL, 'n'}, - {L"print-stack-trace", no_argument, NULL, 't'}, - {NULL, 0, NULL, 0}}; + {L"help", no_argument, nullptr, 'h'}, + {L"current-filename", no_argument, nullptr, 'f'}, + {L"current-line-number", no_argument, nullptr, 'n'}, + {L"filename", no_argument, nullptr, 'f'}, + {L"fish-path", no_argument, nullptr, STATUS_FISH_PATH}, + {L"is-block", no_argument, nullptr, 'b'}, + {L"is-command-substitution", no_argument, nullptr, 'c'}, + {L"is-full-job-control", no_argument, nullptr, STATUS_IS_FULL_JOB_CTRL}, + {L"is-interactive", no_argument, nullptr, 'i'}, + {L"is-interactive-job-control", no_argument, nullptr, STATUS_IS_INTERACTIVE_JOB_CTRL}, + {L"is-login", no_argument, nullptr, 'l'}, + {L"is-no-job-control", no_argument, nullptr, STATUS_IS_NO_JOB_CTRL}, + {L"job-control", required_argument, nullptr, 'j'}, + {L"level", required_argument, nullptr, 'L'}, + {L"line", no_argument, nullptr, 'n'}, + {L"line-number", no_argument, nullptr, 'n'}, + {L"print-stack-trace", no_argument, nullptr, 't'}, + {nullptr, 0, nullptr, 0}}; /// Remember the status subcommand and disallow selecting more than one status subcommand. static bool set_status_cmd(wchar_t *const cmd, status_cmd_opts_t &opts, status_cmd_t sub_cmd, @@ -154,7 +154,7 @@ static int parse_cmd_opts(status_cmd_opts_t &opts, int *optind, //!OCLINT(high wchar_t *cmd = argv[0]; int opt; wgetopter_t w; - while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) { + while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, nullptr)) != -1) { switch (opt) { case STATUS_IS_FULL_JOB_CTRL: { if (!set_status_cmd(cmd, opts, STATUS_IS_FULL_JOB_CTRL, streams)) { diff --git a/src/builtin_string.cpp b/src/builtin_string.cpp index b82edb713..9b2453305 100644 --- a/src/builtin_string.cpp +++ b/src/builtin_string.cpp @@ -60,7 +60,7 @@ static bool string_args_from_stdin(const io_streams_t &streams) { } static const wchar_t *string_get_arg_argv(int *argidx, const wchar_t *const *argv) { - return argv && argv[*argidx] ? argv[(*argidx)++] : NULL; + return argv && argv[*argidx] ? argv[(*argidx)++] : nullptr; } // A helper type for extracting arguments from either argv or stdin. @@ -119,13 +119,13 @@ class arg_iterator_t { const wcstring *nextstr() { if (string_args_from_stdin(streams_)) { - return get_arg_stdin() ? &storage_ : NULL; + return get_arg_stdin() ? &storage_ : nullptr; } if (auto arg = string_get_arg_argv(&argidx_, argv_)) { storage_ = arg; return &storage_; } else { - return NULL; + return nullptr; } } }; @@ -176,8 +176,8 @@ typedef struct { //!OCLINT(too many fields) long start = 0; const wchar_t *chars_to_trim = L" \f\n\r\t"; - const wchar_t *arg1 = NULL; - const wchar_t *arg2 = NULL; + const wchar_t *arg1 = nullptr; + const wchar_t *arg2 = nullptr; escape_string_style_t escape_style = STRING_STYLE_SCRIPT; } options_t; @@ -416,27 +416,27 @@ static wcstring construct_short_opts(options_t *opts) { //!OCLINT(high npath co // Note that several long flags share the same short flag. That is okay. The caller is expected // to indicate that a max of one of the long flags sharing a short flag is valid. // Remember: adjust share/completions/string.fish when `string` options change -static const struct woption long_options[] = {{L"all", no_argument, NULL, 'a'}, - {L"chars", required_argument, NULL, 'c'}, - {L"count", required_argument, NULL, 'n'}, - {L"entire", no_argument, NULL, 'e'}, - {L"filter", no_argument, NULL, 'f'}, - {L"ignore-case", no_argument, NULL, 'i'}, - {L"index", no_argument, NULL, 'n'}, - {L"invert", no_argument, NULL, 'v'}, - {L"left", no_argument, NULL, 'l'}, - {L"length", required_argument, NULL, 'l'}, - {L"max", required_argument, NULL, 'm'}, - {L"no-empty", no_argument, NULL, 'n'}, - {L"no-newline", no_argument, NULL, 'N'}, - {L"no-quoted", no_argument, NULL, 'n'}, - {L"quiet", no_argument, NULL, 'q'}, - {L"regex", no_argument, NULL, 'r'}, - {L"right", no_argument, NULL, 'r'}, - {L"start", required_argument, NULL, 's'}, - {L"style", required_argument, NULL, 1}, - {L"no-trim-newlines", no_argument, NULL, 'N'}, - {NULL, 0, NULL, 0}}; +static const struct woption long_options[] = {{L"all", no_argument, nullptr, 'a'}, + {L"chars", required_argument, nullptr, 'c'}, + {L"count", required_argument, nullptr, 'n'}, + {L"entire", no_argument, nullptr, 'e'}, + {L"filter", no_argument, nullptr, 'f'}, + {L"ignore-case", no_argument, nullptr, 'i'}, + {L"index", no_argument, nullptr, 'n'}, + {L"invert", no_argument, nullptr, 'v'}, + {L"left", no_argument, nullptr, 'l'}, + {L"length", required_argument, nullptr, 'l'}, + {L"max", required_argument, nullptr, 'm'}, + {L"no-empty", no_argument, nullptr, 'n'}, + {L"no-newline", no_argument, nullptr, 'N'}, + {L"no-quoted", no_argument, nullptr, 'n'}, + {L"quiet", no_argument, nullptr, 'q'}, + {L"regex", no_argument, nullptr, 'r'}, + {L"right", no_argument, nullptr, 'r'}, + {L"start", required_argument, nullptr, 's'}, + {L"style", required_argument, nullptr, 1}, + {L"no-trim-newlines", no_argument, nullptr, 'N'}, + {nullptr, 0, nullptr, 0}}; static const std::unordered_map flag_to_function = { {'N', handle_flag_N}, {'a', handle_flag_a}, {'c', handle_flag_c}, {'e', handle_flag_e}, @@ -452,7 +452,7 @@ static int parse_opts(options_t *opts, int *optind, int n_req_args, int argc, wc const wchar_t *short_options = short_opts.c_str(); int opt; wgetopter_t w; - while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) { + while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, nullptr)) != -1) { auto fn = flag_to_function.find(opt); if (fn != flag_to_function.end()) { int retval = fn->second(argv, parser, streams, w, opts); @@ -685,7 +685,7 @@ struct compiled_regex_t { compiled_regex_t(const wchar_t *argv0, const wcstring &pattern, bool ignore_case, io_streams_t &streams) - : code(0), match(0) { + : code(nullptr), match(nullptr) { // Disable some sequences that can lead to security problems. uint32_t options = PCRE2_NEVER_UTF; #if PCRE2_CODE_UNIT_WIDTH < 32 @@ -695,10 +695,10 @@ struct compiled_regex_t { int err_code = 0; PCRE2_SIZE err_offset = 0; - code = - pcre2_compile(PCRE2_SPTR(pattern.c_str()), pattern.length(), - options | (ignore_case ? PCRE2_CASELESS : 0), &err_code, &err_offset, 0); - if (code == 0) { + code = pcre2_compile(PCRE2_SPTR(pattern.c_str()), pattern.length(), + options | (ignore_case ? PCRE2_CASELESS : 0), &err_code, &err_offset, + nullptr); + if (code == nullptr) { string_error(streams, _(L"%ls: Regular expression compile error: %ls\n"), argv0, pcre2_strerror(err_code).c_str()); string_error(streams, L"%ls: %ls\n", argv0, pattern.c_str()); @@ -706,15 +706,15 @@ struct compiled_regex_t { return; } - match = pcre2_match_data_create_from_pattern(code, 0); + match = pcre2_match_data_create_from_pattern(code, nullptr); assert(match); } ~compiled_regex_t() { - if (match != 0) { + if (match != nullptr) { pcre2_match_data_free(match); } - if (code != 0) { + if (code != nullptr) { pcre2_code_free(code); } } @@ -785,7 +785,7 @@ class pcre2_matcher_t : public string_matcher_t { bool report_matches(const wcstring &arg) override { // A return value of true means all is well (even if no matches were found), false indicates // an unrecoverable error. - if (regex.code == 0) { + if (regex.code == nullptr) { // pcre2_compile() failed. return false; } @@ -794,8 +794,8 @@ class pcre2_matcher_t : public string_matcher_t { // See pcre2demo.c for an explanation of this logic. PCRE2_SIZE arglen = arg.length(); - int rc = report_match( - arg, pcre2_match(regex.code, PCRE2_SPTR(arg.c_str()), arglen, 0, 0, regex.match, 0)); + int rc = report_match(arg, pcre2_match(regex.code, PCRE2_SPTR(arg.c_str()), arglen, 0, 0, + regex.match, nullptr)); if (rc < 0) { // pcre2 match error. return false; } else if (rc == 0) { // no match @@ -822,7 +822,7 @@ class pcre2_matcher_t : public string_matcher_t { } rc = report_match(arg, pcre2_match(regex.code, PCRE2_SPTR(arg.c_str()), arglen, offset, - options, regex.match, 0)); + options, regex.match, nullptr)); if (rc < 0) { return false; } @@ -1008,7 +1008,7 @@ bool regex_replacer_t::replace_matches(const wcstring &arg) { pcre2_rc = pcre2_substitute(regex.code, PCRE2_SPTR(arg.c_str()), arglen, 0, // start offset options, regex.match, - 0, // match context + nullptr, // match context PCRE2_SPTR(replacement->c_str()), replacement->length(), reinterpret_cast(output), &outlen); @@ -1332,14 +1332,13 @@ static const struct string_subcommand { wchar_t **argv); //!OCLINT(unused param) } -string_subcommands[] = {{L"escape", &string_escape}, {L"join", &string_join}, - {L"join0", &string_join0}, {L"length", &string_length}, - {L"match", &string_match}, {L"replace", &string_replace}, - {L"split", &string_split}, {L"split0", &string_split0}, - {L"sub", &string_sub}, {L"trim", &string_trim}, - {L"lower", &string_lower}, {L"upper", &string_upper}, - {L"repeat", &string_repeat}, {L"unescape", &string_unescape}, - {L"collect", &string_collect}, {NULL, NULL}}; +string_subcommands[] = { + {L"escape", &string_escape}, {L"join", &string_join}, {L"join0", &string_join0}, + {L"length", &string_length}, {L"match", &string_match}, {L"replace", &string_replace}, + {L"split", &string_split}, {L"split0", &string_split0}, {L"sub", &string_sub}, + {L"trim", &string_trim}, {L"lower", &string_lower}, {L"upper", &string_upper}, + {L"repeat", &string_repeat}, {L"unescape", &string_unescape}, {L"collect", &string_collect}, + {nullptr, nullptr}}; /// The string builtin, for manipulating strings. int builtin_string(parser_t &parser, io_streams_t &streams, wchar_t **argv) { @@ -1357,7 +1356,7 @@ int builtin_string(parser_t &parser, io_streams_t &streams, wchar_t **argv) { } const string_subcommand *subcmd = &string_subcommands[0]; - while (subcmd->name != 0 && std::wcscmp(subcmd->name, argv[1]) != 0) { + while (subcmd->name != nullptr && std::wcscmp(subcmd->name, argv[1]) != 0) { subcmd++; } if (!subcmd->handler) { diff --git a/src/builtin_test.cpp b/src/builtin_test.cpp index b821589ac..52d552a28 100644 --- a/src/builtin_test.cpp +++ b/src/builtin_test.cpp @@ -288,7 +288,7 @@ class parenthetical_expression : public expression { }; void test_parser::add_error(const wchar_t *fmt, ...) { - assert(fmt != NULL); + assert(fmt != nullptr); va_list va; va_start(va, fmt); this->errors.push_back(vformat_string(fmt, va)); @@ -296,12 +296,12 @@ void test_parser::add_error(const wchar_t *fmt, ...) { } unique_ptr test_parser::error(const wchar_t *fmt, ...) { - assert(fmt != NULL); + assert(fmt != nullptr); va_list va; va_start(va, fmt); this->errors.push_back(vformat_string(fmt, va)); va_end(va); - return NULL; + return nullptr; } unique_ptr test_parser::parse_unary_expression(unsigned int start, unsigned int end) { @@ -315,7 +315,7 @@ unique_ptr test_parser::parse_unary_expression(unsigned int start, u return make_unique(tok, range_t(start, subject->range.end), move(subject)); } - return NULL; + return nullptr; } return parse_primary(start, end); } @@ -323,7 +323,7 @@ unique_ptr test_parser::parse_unary_expression(unsigned int start, u /// Parse a combining expression (AND, OR). unique_ptr test_parser::parse_combining_expression(unsigned int start, unsigned int end) { - if (start >= end) return NULL; + if (start >= end) return nullptr; std::vector> subjects; std::vector combiners; @@ -363,7 +363,7 @@ unique_ptr test_parser::parse_combining_expression(unsigned int star } if (subjects.empty()) { - return NULL; // no subjects + return nullptr; // no subjects } // Our new expression takes ownership of all expressions we created. The token we pass is // irrelevant. @@ -382,7 +382,7 @@ unique_ptr test_parser::parse_unary_primary(unsigned int start, unsi // All our unary primaries are prefix, so the operator is at start. const token_info_t *info = token_for_string(arg(start)); - if (!(info->flags & UNARY_PRIMARY)) return NULL; + if (!(info->flags & UNARY_PRIMARY)) return nullptr; return make_unique(info->tok, range_t(start, start + 2), arg(start + 1)); } @@ -416,7 +416,7 @@ unique_ptr test_parser::parse_binary_primary(unsigned int start, uns // All our binary primaries are infix, so the operator is at start + 1. const token_info_t *info = token_for_string(arg(start + 1)); - if (!(info->flags & BINARY_PRIMARY)) return NULL; + if (!(info->flags & BINARY_PRIMARY)) return nullptr; return make_unique(info->tok, range_t(start, start + 3), arg(start), arg(start + 2)); @@ -424,15 +424,15 @@ unique_ptr test_parser::parse_binary_primary(unsigned int start, uns unique_ptr test_parser::parse_parenthentical(unsigned int start, unsigned int end) { // We need at least three arguments: open paren, argument, close paren. - if (start + 3 >= end) return NULL; + if (start + 3 >= end) return nullptr; // Must start with an open expression. const token_info_t *open_paren = token_for_string(arg(start)); - if (open_paren->tok != test_paren_open) return NULL; + if (open_paren->tok != test_paren_open) return nullptr; // Parse a subexpression. unique_ptr subexpr = parse_expression(start + 1, end); - if (!subexpr) return NULL; + if (!subexpr) return nullptr; // Parse a close paren. unsigned close_index = subexpr->range.end; @@ -455,7 +455,7 @@ unique_ptr test_parser::parse_primary(unsigned int start, unsigned i return error(L"Missing argument at index %u", start); } - unique_ptr expr = NULL; + unique_ptr expr = nullptr; if (!expr) expr = parse_parenthentical(start, end); if (!expr) expr = parse_unary_primary(start, end); if (!expr) expr = parse_binary_primary(start, end); @@ -466,7 +466,7 @@ unique_ptr test_parser::parse_primary(unsigned int start, unsigned i // See IEEE 1003.1 breakdown of the behavior for different parameter counts. unique_ptr test_parser::parse_3_arg_expression(unsigned int start, unsigned int end) { assert(end - start == 3); - unique_ptr result = NULL; + unique_ptr result = nullptr; const token_info_t *center_token = token_for_string(arg(start + 1)); if (center_token->flags & BINARY_PRIMARY) { @@ -491,7 +491,7 @@ unique_ptr test_parser::parse_3_arg_expression(unsigned int start, u unique_ptr test_parser::parse_4_arg_expression(unsigned int start, unsigned int end) { assert(end - start == 4); - unique_ptr result = NULL; + unique_ptr result = nullptr; token_t first_token = token_for_string(arg(start))->tok; if (first_token == test_bang) { @@ -565,7 +565,7 @@ unique_ptr test_parser::parse_args(const wcstring_list_t &args, wcst static_cast(result->range.end), args.at(result->range.end).c_str()); } - result.reset(NULL); + result.reset(nullptr); } } @@ -641,7 +641,7 @@ static bool parse_double(const wchar_t *arg, double *out_res) { // Consume leading spaces. while (arg && *arg != L'\0' && iswspace(*arg)) arg++; errno = 0; - wchar_t *end = NULL; + wchar_t *end = nullptr; *out_res = fish_wcstod(arg, &end); // Consume trailing spaces. while (end && *end != L'\0' && iswspace(*end)) end++; diff --git a/src/builtin_ulimit.cpp b/src/builtin_ulimit.cpp index d00eb03fc..3fda263d1 100644 --- a/src/builtin_ulimit.cpp +++ b/src/builtin_ulimit.cpp @@ -43,7 +43,7 @@ static const struct resource_t resource_arr[] = { #ifdef RLIMIT_AS {RLIMIT_AS, L"Maximum amount of virtual memory available to the shell", L'v', 1024}, #endif - {0, 0, 0, 0}}; + {0, nullptr, 0, 0}}; /// Get the implicit multiplication factor for the specified resource limit. static int get_multiplier(int what) { @@ -159,25 +159,25 @@ int builtin_ulimit(parser_t &parser, io_streams_t &streams, wchar_t **argv) { static const wchar_t *const short_options = L":HSacdflmnstuvh"; static const struct woption long_options[] = { - {L"all", no_argument, NULL, 'a'}, - {L"hard", no_argument, NULL, 'H'}, - {L"soft", no_argument, NULL, 'S'}, - {L"core-size", no_argument, NULL, 'c'}, - {L"data-size", no_argument, NULL, 'd'}, - {L"file-size", no_argument, NULL, 'f'}, - {L"lock-size", no_argument, NULL, 'l'}, - {L"resident-set-size", no_argument, NULL, 'm'}, - {L"file-descriptor-count", no_argument, NULL, 'n'}, - {L"stack-size", no_argument, NULL, 's'}, - {L"cpu-time", no_argument, NULL, 't'}, - {L"process-count", no_argument, NULL, 'u'}, - {L"virtual-memory-size", no_argument, NULL, 'v'}, - {L"help", no_argument, NULL, 'h'}, - {NULL, 0, NULL, 0}}; + {L"all", no_argument, nullptr, 'a'}, + {L"hard", no_argument, nullptr, 'H'}, + {L"soft", no_argument, nullptr, 'S'}, + {L"core-size", no_argument, nullptr, 'c'}, + {L"data-size", no_argument, nullptr, 'd'}, + {L"file-size", no_argument, nullptr, 'f'}, + {L"lock-size", no_argument, nullptr, 'l'}, + {L"resident-set-size", no_argument, nullptr, 'm'}, + {L"file-descriptor-count", no_argument, nullptr, 'n'}, + {L"stack-size", no_argument, nullptr, 's'}, + {L"cpu-time", no_argument, nullptr, 't'}, + {L"process-count", no_argument, nullptr, 'u'}, + {L"virtual-memory-size", no_argument, nullptr, 'v'}, + {L"help", no_argument, nullptr, 'h'}, + {nullptr, 0, nullptr, 0}}; int opt; wgetopter_t w; - while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) { + while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, nullptr)) != -1) { switch (opt) { case 'a': { report_all = true; diff --git a/src/builtin_wait.cpp b/src/builtin_wait.cpp index a8b39b9ce..f514c09f6 100644 --- a/src/builtin_wait.cpp +++ b/src/builtin_wait.cpp @@ -183,12 +183,12 @@ int builtin_wait(parser_t &parser, io_streams_t &streams, wchar_t **argv) { bool any_flag = false; // flag for -n option static const wchar_t *const short_options = L":n"; - static const struct woption long_options[] = {{L"any", no_argument, NULL, 'n'}, - {NULL, 0, NULL, 0}}; + static const struct woption long_options[] = {{L"any", no_argument, nullptr, 'n'}, + {nullptr, 0, nullptr, 0}}; int opt; wgetopter_t w; - while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) { + while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, nullptr)) != -1) { switch (opt) { case 'n': any_flag = true; diff --git a/src/common.cpp b/src/common.cpp index f251db257..9fa1b5586 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -137,7 +137,7 @@ long convert_digit(wchar_t d, int base) { } /// Test whether the char is a valid hex digit as used by the `escape_string_*()` functions. -static bool is_hex_digit(int c) { return std::strchr("0123456789ABCDEF", c) != NULL; } +static bool is_hex_digit(int c) { return std::strchr("0123456789ABCDEF", c) != nullptr; } /// This is a specialization of `convert_digit()` that only handles base 16 and only uppercase. long convert_hex_digit(wchar_t d) { @@ -216,13 +216,14 @@ bool is_windows_subsystem_for_linux() { for (int i = skip_levels; i < n_frames; i++) { Dl_info info; if (dladdr(callstack[i], &info) && info.dli_sname) { - char *demangled = NULL; + char *demangled = nullptr; int status = -1; if (info.dli_sname[0] == '_') - demangled = abi::__cxa_demangle(info.dli_sname, NULL, 0, &status); - swprintf(text, sizeof(text) / sizeof(wchar_t), L"%-3d %s + %td", i - skip_levels, - status == 0 ? demangled : info.dli_sname == 0 ? symbols[i] : info.dli_sname, - static_cast(callstack[i]) - static_cast(info.dli_saddr)); + demangled = abi::__cxa_demangle(info.dli_sname, nullptr, nullptr, &status); + swprintf( + text, sizeof(text) / sizeof(wchar_t), L"%-3d %s + %td", i - skip_levels, + status == 0 ? demangled : info.dli_sname == nullptr ? symbols[i] : info.dli_sname, + static_cast(callstack[i]) - static_cast(info.dli_saddr)); free(demangled); } else { swprintf(text, sizeof(text) / sizeof(wchar_t), L"%-3d %s", i - skip_levels, symbols[i]); @@ -287,7 +288,7 @@ int fgetws2(wcstring *s, FILE *f) { /// area. static wcstring str2wcs_internal(const char *in, const size_t in_len) { if (in_len == 0) return wcstring(); - assert(in != NULL); + assert(in != nullptr); wcstring result; result.reserve(in_len); @@ -375,7 +376,7 @@ wcstring str2wcstring(const std::string &in, size_t len) { } char *wcs2str(const wchar_t *in, size_t len) { - if (!in) return NULL; + if (!in) return nullptr; size_t desired_size = MAX_UTF8_BYTES * len + 1; char local_buff[512]; if (desired_size <= sizeof local_buff / sizeof *local_buff) { @@ -507,7 +508,7 @@ void append_formatv(wcstring &target, const wchar_t *format, va_list va_orig) { const size_t max_size = (128 * 1024 * 1024); wchar_t static_buff[256]; size_t size = 0; - wchar_t *buff = NULL; + wchar_t *buff = nullptr; int status = -1; while (status < 0) { // Reallocate if necessary. @@ -520,8 +521,8 @@ void append_formatv(wcstring &target, const wchar_t *format, va_list va_orig) { buff[0] = '\0'; break; } - buff = static_cast(realloc((buff == static_buff ? NULL : buff), size)); - assert(buff != NULL); + buff = static_cast(realloc((buff == static_buff ? nullptr : buff), size)); + assert(buff != nullptr); } // Try printing. @@ -559,18 +560,18 @@ wchar_t *quote_end(const wchar_t *pos) { while (1) { pos++; - if (!*pos) return 0; + if (!*pos) return nullptr; if (*pos == L'\\') { pos++; - if (!*pos) return 0; + if (!*pos) return nullptr; } else { if (*pos == c) { return const_cast(pos); } } } - return 0; + return nullptr; } void fish_setlocale() { @@ -720,7 +721,7 @@ void debug_safe(int level, const char *msg, const char *param1, const char *para const char *cursor = msg; while (*cursor != '\0') { const char *end = std::strchr(cursor, '%'); - if (end == NULL) end = cursor + std::strlen(cursor); + if (end == nullptr) end = cursor + std::strlen(cursor); ignore_result(write(STDERR_FILENO, cursor, end - cursor)); @@ -1721,7 +1722,7 @@ static bool unescape_string_internal(const wchar_t *const input, const size_t in } bool unescape_string_in_place(wcstring *str, unescape_flags_t escape_special) { - assert(str != NULL); + assert(str != nullptr); wcstring output; bool success = unescape_string_internal(str->c_str(), str->size(), &output, escape_special); if (success) { @@ -2145,7 +2146,7 @@ int create_directory(const wcstring &d) { wcstring format_size(long long sz) { wcstring result; - const wchar_t *sz_name[] = {L"kB", L"MB", L"GB", L"TB", L"PB", L"EB", L"ZB", L"YB", 0}; + const wchar_t *sz_name[] = {L"kB", L"MB", L"GB", L"TB", L"PB", L"EB", L"ZB", L"YB", nullptr}; if (sz < 0) { result.append(L"unknown"); @@ -2201,7 +2202,7 @@ void format_size_safe(char buff[128], unsigned long long sz) { const size_t max_len = buff_size - 1; // need to leave room for a null terminator std::memset(buff, 0, buff_size); size_t idx = 0; - const char *const sz_name[] = {"kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB", NULL}; + const char *const sz_name[] = {"kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB", nullptr}; if (sz < 1) { strncpy(buff, "empty", buff_size); } else if (sz < 1024) { @@ -2235,7 +2236,7 @@ void format_size_safe(char buff[128], unsigned long long sz) { /// the gettimeofday function and will have the same precision as that function. double timef() { struct timeval tv; - assert_with_errno(gettimeofday(&tv, 0) != -1); + assert_with_errno(gettimeofday(&tv, nullptr) != -1); // return (double)tv.tv_sec + 0.000001 * tv.tv_usec; return static_cast(tv.tv_sec) + 1e-6 * tv.tv_usec; } @@ -2389,7 +2390,7 @@ static CharType_t **make_null_terminated_array_helper( // Now allocate their sum. unsigned char *base = static_cast(malloc(pointers_allocation_len + strings_allocation_len)); - if (!base) return NULL; + if (!base) return nullptr; // Divvy it up into the pointers and strings. CharType_t **pointers = reinterpret_cast(base); @@ -2402,7 +2403,7 @@ static CharType_t **make_null_terminated_array_helper( strings = std::copy(str.begin(), str.end(), strings); // copy the string into strings *strings++ = (CharType_t)(0); // each string needs a null terminator } - *pointers++ = NULL; // array of pointers needs a null terminator + *pointers++ = nullptr; // array of pointers needs a null terminator // Make sure we know what we're doing. assert((unsigned char *)pointers - base == (std::ptrdiff_t)pointers_allocation_len); diff --git a/src/common.h b/src/common.h index f32e7e11a..9a9acf6df 100644 --- a/src/common.h +++ b/src/common.h @@ -475,11 +475,13 @@ void format_size_safe(char buff[128], unsigned long long sz); /// Our crappier versions of debug which is guaranteed to not allocate any memory, or do anything /// other than call write(). This is useful after a call to fork() with threads. -void debug_safe(int level, const char *msg, const char *param1 = NULL, const char *param2 = NULL, - const char *param3 = NULL, const char *param4 = NULL, const char *param5 = NULL, - const char *param6 = NULL, const char *param7 = NULL, const char *param8 = NULL, - const char *param9 = NULL, const char *param10 = NULL, const char *param11 = NULL, - const char *param12 = NULL); +void debug_safe(int level, const char *msg, const char *param1 = nullptr, + const char *param2 = nullptr, const char *param3 = nullptr, + const char *param4 = nullptr, const char *param5 = nullptr, + const char *param6 = nullptr, const char *param7 = nullptr, + const char *param8 = nullptr, const char *param9 = nullptr, + const char *param10 = nullptr, const char *param11 = nullptr, + const char *param12 = nullptr); /// Writes out a long safely. void format_long_safe(char buff[64], long val); @@ -529,7 +531,7 @@ char **make_null_terminated_array(const std::vector &lst); // Helper class for managing a null-terminated array of null-terminated strings (of some char type). template class null_terminated_array_t { - CharType_t **array{NULL}; + CharType_t **array{nullptr}; // No assignment or copying. void operator=(null_terminated_array_t rhs) = delete; @@ -539,8 +541,8 @@ class null_terminated_array_t { size_t size() const { size_t len = 0; - if (array != NULL) { - while (array[len] != NULL) { + if (array != nullptr) { + while (array[len] != nullptr) { len++; } } @@ -549,7 +551,7 @@ class null_terminated_array_t { void free(void) { ::free((void *)array); - array = NULL; + array = nullptr; } public: @@ -951,7 +953,7 @@ static const wchar_t *enum_to_str(T enum_val, const enum_map map[]) { return entry->str; } } - return NULL; + return nullptr; }; void redirect_tty_output(); diff --git a/src/complete.cpp b/src/complete.cpp index d4c8d1530..bed7593ac 100644 --- a/src/complete.cpp +++ b/src/complete.cpp @@ -197,7 +197,7 @@ static complete_flags_t resolve_auto_space(const wcstring &comp, complete_flags_ if (flags & COMPLETE_AUTO_SPACE) { new_flags &= ~COMPLETE_AUTO_SPACE; size_t len = comp.size(); - if (len > 0 && (std::wcschr(L"/=@:", comp.at(len - 1)) != 0)) + if (len > 0 && (std::wcschr(L"/=@:", comp.at(len - 1)) != nullptr)) new_flags |= COMPLETE_NO_SPACE; } return new_flags; @@ -681,7 +681,7 @@ void completer_t::complete_cmd(const wcstring &str_cmd) { expand_string(str_cmd, &this->completions, this->expand_flags() | expand_flag::special_for_command | expand_flag::for_completions | expand_flag::executables_only, - vars, parser, NULL); + vars, parser, nullptr); if (result != expand_result_t::error && this->wants_descriptions()) { this->complete_cmd_desc(str_cmd); } @@ -693,7 +693,7 @@ void completer_t::complete_cmd(const wcstring &str_cmd) { expand_string( str_cmd, &this->completions, this->expand_flags() | expand_flag::for_completions | expand_flag::directories_only, - vars, parser, NULL); + vars, parser, nullptr); UNUSED(ignore); if (str_cmd.empty() || (str_cmd.find(L'/') == wcstring::npos && str_cmd.at(0) != L'~')) { @@ -793,18 +793,18 @@ static bool param_match(const complete_entry_opt_t *e, const wchar_t *optstr) { static const wchar_t *param_match2(const complete_entry_opt_t *e, const wchar_t *optstr) { // We may get a complete_entry_opt_t with no options if it's just arguments. if (e->option.empty()) { - return NULL; + return nullptr; } // Verify leading dashes. size_t cursor = leading_dash_count(optstr); if (cursor != e->expected_dash_count()) { - return NULL; + return nullptr; } // Verify options match. if (!string_prefixes_string(e->option, &optstr[cursor])) { - return NULL; + return nullptr; } cursor += e->option.length(); @@ -812,7 +812,7 @@ static const wchar_t *param_match2(const complete_entry_opt_t *e, const wchar_t // sign for long options. assert(e->type != option_type_short); if (optstr[cursor] != L'=') { - return NULL; + return nullptr; } cursor += 1; return &optstr[cursor]; @@ -954,7 +954,7 @@ bool completer_t::complete_param(const wcstring &cmd_orig, const wcstring &popt, } else { arg = param_match2(&o, str.c_str()); } - if (arg != NULL && this->condition_test(o.condition)) { + if (arg != nullptr && this->condition_test(o.condition)) { if (o.result_mode.requires_param) use_common = false; if (o.result_mode.no_files) use_files = false; if (o.result_mode.force_files) has_force = true; @@ -1136,7 +1136,7 @@ void completer_t::complete_param_expand(const wcstring &str, bool do_file, // See #4954. const wcstring sep_string = wcstring(str, sep_index + 1); std::vector local_completions; - if (expand_string(sep_string, &local_completions, flags, vars, parser, NULL) == + if (expand_string(sep_string, &local_completions, flags, vars, parser, nullptr) == expand_result_t::error) { debug(3, L"Error while expanding string '%ls'", sep_string.c_str()); } @@ -1156,7 +1156,7 @@ void completer_t::complete_param_expand(const wcstring &str, bool do_file, // consider relaxing this if there was a preceding double-dash argument. if (string_prefixes_string(L"-", str)) flags.clear(expand_flag::fuzzy_match); - if (expand_string(str, &this->completions, flags, vars, parser, NULL) == + if (expand_string(str, &this->completions, flags, vars, parser, nullptr) == expand_result_t::error) { debug(3, L"Error while expanding string '%ls'", str.c_str()); } @@ -1638,7 +1638,7 @@ void complete(const wcstring &cmd_with_subcmds, std::vector *out_c const wchar_t *cmdsubst_begin, *cmdsubst_end; parse_util_cmdsubst_extent(cmd_with_subcmds.c_str(), cmd_with_subcmds.size(), &cmdsubst_begin, &cmdsubst_end); - assert(cmdsubst_begin != NULL && cmdsubst_end != NULL && cmdsubst_end >= cmdsubst_begin); + assert(cmdsubst_begin != nullptr && cmdsubst_end != nullptr && cmdsubst_end >= cmdsubst_begin); wcstring cmd = wcstring(cmdsubst_begin, cmdsubst_end - cmdsubst_begin); completer_t completer(vars, parser, std::move(cmd), flags); completer.perform(); diff --git a/src/env.cpp b/src/env.cpp index 2eac7d73f..7cfe7c0bb 100644 --- a/src/env.cpp +++ b/src/env.cpp @@ -206,7 +206,7 @@ void misc_init() { // issue #3748. if (isatty(STDOUT_FILENO)) { fflush(stdout); - setvbuf(stdout, NULL, _IONBF, 0); + setvbuf(stdout, nullptr, _IONBF, 0); } } @@ -253,7 +253,7 @@ void env_init(const struct config_paths_t *paths /* or NULL */) { } // Set the given paths in the environment, if we have any. - if (paths != NULL) { + if (paths != nullptr) { vars.set_one(FISH_DATADIR_VAR, ENV_GLOBAL, paths->data); vars.set_one(FISH_SYSCONFDIR_VAR, ENV_GLOBAL, paths->sysconf); vars.set_one(FISH_HELPDIR_VAR, ENV_GLOBAL, paths->doc); @@ -392,7 +392,7 @@ void env_init(const struct config_paths_t *paths /* or NULL */) { static int set_umask(const wcstring_list_t &list_val) { long mask = -1; if (list_val.size() == 1 && !list_val.front().empty()) { - mask = fish_wcstol(list_val.front().c_str(), NULL, 8); + mask = fish_wcstol(list_val.front().c_str(), nullptr, 8); } if (errno || mask > 0777 || mask < 0) return ENV_INVALID; @@ -1401,14 +1401,14 @@ wcstring env_get_runtime_path() { // Check that the path is actually usable. Technically this is guaranteed by the fdo spec but in // practice it is not always the case: see #1828 and #2222. int mode = R_OK | W_OK | X_OK; - if (dir != NULL && access(dir, mode) == 0 && check_runtime_path(dir) == 0) { + if (dir != nullptr && access(dir, mode) == 0 && check_runtime_path(dir) == 0) { result = str2wcstring(dir); } else { // Don't rely on $USER being set, as setup_user() has not yet been called. // See https://github.com/fish-shell/fish-shell/issues/5180 // getpeuid() can't fail, but getpwuid sure can. auto pwuid = getpwuid(geteuid()); - const char *uname = pwuid ? pwuid->pw_name : NULL; + const char *uname = pwuid ? pwuid->pw_name : nullptr; // /tmp/fish.user std::string tmpdir = get_path_to_tmp_dir() + "/fish."; if (uname) { diff --git a/src/env.h b/src/env.h index 454cfd94f..190ef08bf 100644 --- a/src/env.h +++ b/src/env.h @@ -79,7 +79,7 @@ struct statuses_t { }; /// Initialize environment variable data. -void env_init(const struct config_paths_t *paths = NULL); +void env_init(const struct config_paths_t *paths = nullptr); /// Various things we need to initialize at run-time that don't really fit any of the other init /// routines. diff --git a/src/env_dispatch.cpp b/src/env_dispatch.cpp index bf70a41cd..c3b959d4b 100644 --- a/src/env_dispatch.cpp +++ b/src/env_dispatch.cpp @@ -164,7 +164,7 @@ static void guess_emoji_width(const environment_t &vars) { double version = 0; if (auto version_var = vars.get(L"TERM_PROGRAM_VERSION")) { std::string narrow_version = wcs2string(version_var->as_string()); - version = strtod(narrow_version.c_str(), NULL); + version = strtod(narrow_version.c_str(), nullptr); } if (term == L"Apple_Terminal" && version >= 400) { @@ -349,7 +349,7 @@ static void update_fish_color_support(const environment_t &vars) { if (auto tp = vars.get(L"TERM_PROGRAM")) term_program = tp->as_string(); if (auto tpv = vars.get(L"TERM_PROGRAM_VERSION")) { if (term_program == L"Apple_Terminal" && - fish_wcstod(tpv->as_string().c_str(), NULL) > 299) { + fish_wcstod(tpv->as_string().c_str(), nullptr) > 299) { // OS X Lion is version 299+, it has 256 color support (see github Wiki) support_term256 = true; debug(2, L"256 color support enabled for TERM=%ls on Terminal.app", term.c_str()); @@ -358,7 +358,7 @@ static void update_fish_color_support(const environment_t &vars) { debug(2, L"256 color support enabled for TERM=%ls", term.c_str()); } } - } else if (cur_term != NULL) { + } else if (cur_term != nullptr) { // See if terminfo happens to identify 256 colors support_term256 = (max_colors >= 256); debug(2, L"256 color support: %d colors per terminfo entry for %ls", max_colors, @@ -455,7 +455,7 @@ static void init_curses(const environment_t &vars) { } int err_ret; - if (setupterm(NULL, STDOUT_FILENO, &err_ret) == ERR) { + if (setupterm(nullptr, STDOUT_FILENO, &err_ret) == ERR) { auto term = vars.get(L"TERM"); if (is_interactive_session()) { debug(1, _(L"Could not set up terminal.")); @@ -484,7 +484,7 @@ static void init_curses(const environment_t &vars) { static void init_locale(const environment_t &vars) { // We have to make a copy because the subsequent setlocale() call to change the locale will // invalidate the pointer from the this setlocale() call. - char *old_msg_locale = strdup(setlocale(LC_MESSAGES, NULL)); + char *old_msg_locale = strdup(setlocale(LC_MESSAGES, nullptr)); for (const auto &var_name : locale_variables) { const auto var = vars.get(var_name, ENV_EXPORT); @@ -503,7 +503,7 @@ static void init_locale(const environment_t &vars) { fish_setlocale(); FLOGF(env_locale, L"init_locale() setlocale(): '%s'", locale); - const char *new_msg_locale = setlocale(LC_MESSAGES, NULL); + const char *new_msg_locale = setlocale(LC_MESSAGES, nullptr); FLOGF(env_locale, L"old LC_MESSAGES locale: '%s'", old_msg_locale); FLOGF(env_locale, L"new LC_MESSAGES locale: '%s'", new_msg_locale); #ifdef HAVE__NL_MSG_CAT_CNTR diff --git a/src/env_universal_common.cpp b/src/env_universal_common.cpp index c091a3526..d6933c080 100644 --- a/src/env_universal_common.cpp +++ b/src/env_universal_common.cpp @@ -174,8 +174,8 @@ static bool append_utf8(const wcstring &input, std::string *receiver, std::strin static bool append_file_entry(env_var_t::env_var_flags_t flags, const wcstring &key_in, const wcstring &val_in, std::string *result, std::string *storage) { namespace f3 = fish3_uvars; - assert(storage != NULL); - assert(result != NULL); + assert(storage != nullptr); + assert(result != nullptr); // Record the length on entry, in case we need to back up. bool success = true; @@ -1069,7 +1069,7 @@ class universal_notifier_shmem_poller_t : public universal_notifier_t { volatile universal_notifier_shmem_t *region; void open_shmem() { - assert(region == NULL); + assert(region == nullptr); // Use a path based on our uid to avoid collisions. char path[NAME_MAX]; @@ -1108,13 +1108,13 @@ class universal_notifier_shmem_poller_t : public universal_notifier_t { // Memory map the region. if (!errored) { - void *addr = mmap(NULL, sizeof(universal_notifier_shmem_t), PROT_READ | PROT_WRITE, + void *addr = mmap(nullptr, sizeof(universal_notifier_shmem_t), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (addr == MAP_FAILED) { const char *error = std::strerror(errno); FLOGF(error, _(L"Unable to memory map shared memory object with path '%s': %s"), path, error); - this->region = NULL; + this->region = nullptr; } else { this->region = static_cast(addr); } @@ -1136,7 +1136,7 @@ class universal_notifier_shmem_poller_t : public universal_notifier_t { // This isn't "safe" in the sense that multiple simultaneous increments may result in one being // lost, but it should always result in the value being changed, which is sufficient. void post_notification() { - if (region != NULL) { + if (region != nullptr) { /* Read off the seed */ uint32_t seed = ntohl(region->universal_variable_seed); //!OCLINT(constant cond op) @@ -1153,12 +1153,12 @@ class universal_notifier_shmem_poller_t : public universal_notifier_t { } } - universal_notifier_shmem_poller_t() : last_change_time(0), last_seed(0), region(NULL) { + universal_notifier_shmem_poller_t() : last_change_time(0), last_seed(0), region(nullptr) { open_shmem(); } ~universal_notifier_shmem_poller_t() { - if (region != NULL) { + if (region != nullptr) { // Behold: C++ in all its glory! void *address = const_cast(static_cast(region)); if (munmap(address, sizeof(universal_notifier_shmem_t)) < 0) { @@ -1169,7 +1169,7 @@ class universal_notifier_shmem_poller_t : public universal_notifier_t { bool poll() { bool result = false; - if (region != NULL) { + if (region != nullptr) { uint32_t seed = ntohl(region->universal_variable_seed); //!OCLINT(constant cond op) if (seed != last_seed) { result = true; @@ -1424,7 +1424,7 @@ class universal_notifier_named_pipe_t : public universal_notifier_t { FD_ZERO(&fds); FD_SET(this->pipe_fd, &fds); struct timeval timeout = {}; - select(this->pipe_fd + 1, &fds, NULL, NULL, &timeout); + select(this->pipe_fd + 1, &fds, nullptr, nullptr, &timeout); if (!FD_ISSET(this->pipe_fd, &fds)) { // No longer readable, no longer polling. polling_due_to_readable_fd = false; @@ -1477,7 +1477,7 @@ std::unique_ptr universal_notifier_t::new_notifier_for_str } } DIE("should never reach this statement"); - return NULL; + return nullptr; } // Default implementations. diff --git a/src/env_universal_common.h b/src/env_universal_common.h index e023b8fba..12d12d3c2 100644 --- a/src/env_universal_common.h +++ b/src/env_universal_common.h @@ -183,7 +183,7 @@ class universal_notifier_t { // Factory constructor. static std::unique_ptr new_notifier_for_strategy( - notifier_strategy_t strat, const wchar_t *test_path = NULL); + notifier_strategy_t strat, const wchar_t *test_path = nullptr); // Default instance. Other instances are possible for testing. static universal_notifier_t &default_notifier(); diff --git a/src/event.h b/src/event.h index 1913d2e8b..13a6dd677 100644 --- a/src/event.h +++ b/src/event.h @@ -121,7 +121,8 @@ void event_print(io_streams_t &streams, maybe_t type_filter); wcstring event_get_desc(const event_t &e); /// Fire a generic event with the specified name. -void event_fire_generic(parser_t &parser, const wchar_t *name, const wcstring_list_t *args = NULL); +void event_fire_generic(parser_t &parser, const wchar_t *name, + const wcstring_list_t *args = nullptr); /// Return the event type for a given name, or none. maybe_t event_type_for_name(const wcstring &name); diff --git a/src/exec.cpp b/src/exec.cpp index 02f6db8bb..3e78a01be 100644 --- a/src/exec.cpp +++ b/src/exec.cpp @@ -113,7 +113,7 @@ char *get_interpreter(const char *command, char *interpreter, size_t buff_size) return interpreter + 2; } - return NULL; + return nullptr; } /// This function is executed by the child process created by a call to fork(). It should be called @@ -151,7 +151,7 @@ static void safe_launch_process(process_t *p, const char *actual_cmd, const char argv2[0] = sh_command; for (size_t i = 1; i < sizeof argv2 / sizeof *argv2; i++) { argv2[i] = argv[i - 1]; - if (argv2[i] == NULL) break; + if (argv2[i] == nullptr) break; } execve(sh_command, argv2, envv); @@ -192,7 +192,7 @@ static bool resolve_file_redirections_to_fds(const io_chain_t &in_chain, const w io_chain_t *out_chain, std::vector *out_opened_fds) { ASSERT_IS_MAIN_THREAD(); - assert(out_chain != NULL && out_opened_fds != NULL); + assert(out_chain != nullptr && out_opened_fds != nullptr); assert(out_chain->empty()); // Just to be clear what we do for an empty chain. @@ -1245,7 +1245,7 @@ static int exec_subshell_internal(const wcstring &cmd, parser_t &parser, wcstrin parser.libdata().is_subshell = prev_subshell; - if (lst == NULL || !buffer) { + if (lst == nullptr || !buffer) { return subcommand_statuses.status; } // Walk over all the elements. @@ -1266,7 +1266,7 @@ static int exec_subshell_internal(const wcstring &cmd, parser_t &parser, wcstrin // Look for the next separator. const char *stop = static_cast(std::memchr(cursor, '\n', end - cursor)); - const bool hit_separator = (stop != NULL); + const bool hit_separator = (stop != nullptr); if (!hit_separator) { // If it's not found, just use the end. stop = end; @@ -1297,5 +1297,5 @@ int exec_subshell(const wcstring &cmd, parser_t &parser, wcstring_list_t &output int exec_subshell(const wcstring &cmd, parser_t &parser, bool apply_exit_status, bool is_subcmd) { ASSERT_IS_MAIN_THREAD(); - return exec_subshell_internal(cmd, parser, NULL, apply_exit_status, is_subcmd); + return exec_subshell_internal(cmd, parser, nullptr, apply_exit_status, is_subcmd); } diff --git a/src/expand.cpp b/src/expand.cpp index 71ef2ce31..1f4563337 100644 --- a/src/expand.cpp +++ b/src/expand.cpp @@ -68,7 +68,7 @@ static bool expand_is_clean(const wcstring &in) { if (in.empty()) return true; // Test characters that have a special meaning in the first character position. - if (std::wcschr(UNCLEAN_FIRST, in.at(0)) != NULL) return false; + if (std::wcschr(UNCLEAN_FIRST, in.at(0)) != nullptr) return false; // Test characters that have a special meaning in any character position. return in.find_first_of(UNCLEAN) == wcstring::npos; @@ -457,8 +457,8 @@ static expand_result_t expand_braces(const wcstring &instr, expand_flags_t flags bool syntax_error = false; int brace_count = 0; - const wchar_t *brace_begin = NULL, *brace_end = NULL; - const wchar_t *last_sep = NULL; + const wchar_t *brace_begin = nullptr, *brace_end = nullptr; + const wchar_t *last_sep = nullptr; const wchar_t *item_begin; size_t length_preceding_braces, length_following_braces, tot_len; @@ -518,7 +518,7 @@ static expand_result_t expand_braces(const wcstring &instr, expand_flags_t flags return expand_result_t::error; } - if (brace_begin == NULL) { + if (brace_begin == nullptr) { append_completion(out, instr); return expand_result_t::ok; } diff --git a/src/expand.h b/src/expand.h index 294be885e..be08676b3 100644 --- a/src/expand.h +++ b/src/expand.h @@ -148,7 +148,7 @@ __warn_unused expand_result_t expand_string(wcstring input, std::vector &parser, parse_error_list_t *errors = NULL); + const std::shared_ptr &parser, parse_error_list_t *errors = nullptr); /// Expand a command string like $HOME/bin/cmd into a command and list of arguments. /// Return the command and arguments by reference. @@ -158,7 +158,7 @@ bool expand_one(wcstring &string, expand_flags_t flags, const environment_t &var // \return an expand error. expand_result_t expand_to_command_and_args(const wcstring &instr, const environment_t &vars, wcstring *out_cmd, wcstring_list_t *out_args, - parse_error_list_t *errors = NULL); + parse_error_list_t *errors = nullptr); /// Convert the variable value to a human readable form, i.e. escape things, handle arrays, etc. /// Suitable for pretty-printing. diff --git a/src/fallback.cpp b/src/fallback.cpp index c7ab786dc..c612625a4 100644 --- a/src/fallback.cpp +++ b/src/fallback.cpp @@ -78,8 +78,8 @@ int fish_mkstemp_cloexec(char *name_template) { [[gnu::unused]] static wchar_t *wcsdup_fallback(const wchar_t *in) { size_t len = std::wcslen(in); wchar_t *out = static_cast(malloc(sizeof(wchar_t) * (len + 1))); - if (out == 0) { - return 0; + if (out == nullptr) { + return nullptr; } std::memcpy(out, in, sizeof(wchar_t) * (len + 1)); @@ -163,8 +163,8 @@ int wcsncasecmp(const wchar_t *a, const wchar_t *b, size_t n) { #ifndef HAVE_WCSNDUP wchar_t *wcsndup(const wchar_t *in, size_t c) { wchar_t *res = static_cast(malloc(sizeof(wchar_t) * (c + 1))); - if (res == 0) { - return 0; + if (res == nullptr) { + return nullptr; } wcslcpy(res, in, c + 1); return res; diff --git a/src/fish.cpp b/src/fish.cpp index e1284c3f3..2a2fc964c 100644 --- a/src/fish.cpp +++ b/src/fish.cpp @@ -79,7 +79,7 @@ class fish_cmd_opts_t { }; /// If we are doing profiling, the filename to output to. -static const char *s_profiling_output_filename = NULL; +static const char *s_profiling_output_filename = nullptr; /// \return a timeval converted to milliseconds. long long tv_to_msec(const struct timeval &tv) { @@ -127,7 +127,7 @@ static bool get_realpath(std::string &path) { if ((ptr = realpath(path.c_str(), buff))) { path = ptr; } - return ptr != NULL; + return ptr != nullptr; } static struct config_paths_t determine_config_directory_paths(const char *argv0) { @@ -157,7 +157,7 @@ static struct config_paths_t determine_config_directory_paths(const char *argv0) // The next check is that we are in a reloctable directory tree const char *installed_suffix = "/bin/fish"; const char *just_a_fish = "/fish"; - const char *suffix = NULL; + const char *suffix = nullptr; if (has_suffix(exec_path, installed_suffix, false)) { suffix = installed_suffix; @@ -263,25 +263,26 @@ int run_command_list(std::vector *cmds, const io_chain_t &io) { /// Parse the argument list, return the index of the first non-flag arguments. static int fish_parse_opt(int argc, char **argv, fish_cmd_opts_t *opts) { static const char *const short_opts = "+hPilnvc:C:p:d:f:D:"; - static const struct option long_opts[] = {{"command", required_argument, NULL, 'c'}, - {"init-command", required_argument, NULL, 'C'}, - {"features", required_argument, NULL, 'f'}, - {"debug", required_argument, NULL, 'd'}, - {"debug-output", required_argument, NULL, 'o'}, - {"debug-stack-frames", required_argument, NULL, 'D'}, - {"interactive", no_argument, NULL, 'i'}, - {"login", no_argument, NULL, 'l'}, - {"no-execute", no_argument, NULL, 'n'}, - {"print-rusage-self", no_argument, NULL, 1}, - {"print-debug-categories", no_argument, NULL, 2}, - {"profile", required_argument, NULL, 'p'}, - {"private", no_argument, NULL, 'P'}, - {"help", no_argument, NULL, 'h'}, - {"version", no_argument, NULL, 'v'}, - {NULL, 0, NULL, 0}}; + static const struct option long_opts[] = { + {"command", required_argument, nullptr, 'c'}, + {"init-command", required_argument, nullptr, 'C'}, + {"features", required_argument, nullptr, 'f'}, + {"debug", required_argument, nullptr, 'd'}, + {"debug-output", required_argument, nullptr, 'o'}, + {"debug-stack-frames", required_argument, nullptr, 'D'}, + {"interactive", no_argument, nullptr, 'i'}, + {"login", no_argument, nullptr, 'l'}, + {"no-execute", no_argument, nullptr, 'n'}, + {"print-rusage-self", no_argument, nullptr, 1}, + {"print-debug-categories", no_argument, nullptr, 2}, + {"profile", required_argument, nullptr, 'p'}, + {"private", no_argument, nullptr, 'P'}, + {"help", no_argument, nullptr, 'h'}, + {"version", no_argument, nullptr, 'v'}, + {nullptr, 0, nullptr, 0}}; int opt; - while ((opt = getopt_long(argc, argv, short_opts, long_opts, NULL)) != -1) { + while ((opt = getopt_long(argc, argv, short_opts, long_opts, nullptr)) != -1) { switch (opt) { case 'c': { opts->batch_cmds.push_back(optarg); @@ -413,7 +414,7 @@ int main(int argc, char **argv) { // struct stat tmp; // stat("----------FISH_HIT_MAIN----------", &tmp); - const char *dummy_argv[2] = {"fish", NULL}; + const char *dummy_argv[2] = {"fish", nullptr}; if (!argv[0]) { argv = (char **)dummy_argv; //!OCLINT(parameter reassignment) argc = 1; //!OCLINT(parameter reassignment) diff --git a/src/fish_indent.cpp b/src/fish_indent.cpp index 624f725e2..0444f97b3 100644 --- a/src/fish_indent.cpp +++ b/src/fish_indent.cpp @@ -353,7 +353,7 @@ static wcstring prettify(const wcstring &src, bool do_indent) { parse_node_tree_t parse_tree; int parse_flags = (parse_flag_continue_after_error | parse_flag_include_comments | parse_flag_leave_unterminated | parse_flag_show_blank_lines); - if (!parse_tree_from_string(src, parse_flags, &parse_tree, NULL)) { + if (!parse_tree_from_string(src, parse_flags, &parse_tree, nullptr)) { return src; // we return the original string on failure } @@ -508,20 +508,20 @@ int main(int argc, char *argv[]) { bool do_indent = true; const char *short_opts = "+d:hvwiD:"; - const struct option long_opts[] = {{"debug-level", required_argument, NULL, 'd'}, - {"debug-stack-frames", required_argument, NULL, 'D'}, - {"dump-parse-tree", no_argument, NULL, 'P'}, - {"no-indent", no_argument, NULL, 'i'}, - {"help", no_argument, NULL, 'h'}, - {"version", no_argument, NULL, 'v'}, - {"write", no_argument, NULL, 'w'}, - {"html", no_argument, NULL, 1}, - {"ansi", no_argument, NULL, 2}, - {"pygments", no_argument, NULL, 3}, - {NULL, 0, NULL, 0}}; + const struct option long_opts[] = {{"debug-level", required_argument, nullptr, 'd'}, + {"debug-stack-frames", required_argument, nullptr, 'D'}, + {"dump-parse-tree", no_argument, nullptr, 'P'}, + {"no-indent", no_argument, nullptr, 'i'}, + {"help", no_argument, nullptr, 'h'}, + {"version", no_argument, nullptr, 'v'}, + {"write", no_argument, nullptr, 'w'}, + {"html", no_argument, nullptr, 1}, + {"ansi", no_argument, nullptr, 2}, + {"pygments", no_argument, nullptr, 3}, + {nullptr, 0, nullptr, 0}}; int opt; - while ((opt = getopt_long(argc, argv, short_opts, long_opts, NULL)) != -1) { + while ((opt = getopt_long(argc, argv, short_opts, long_opts, nullptr)) != -1) { switch (opt) { case 'P': { dump_parse_tree = true; @@ -633,7 +633,7 @@ int main(int argc, char *argv[]) { // Maybe colorize. std::vector colors; if (output_type != output_type_plain_text) { - highlight_shell_no_io(output_wtext, colors, output_wtext.size(), NULL, + highlight_shell_no_io(output_wtext, colors, output_wtext.size(), nullptr, env_stack_t::globals()); } diff --git a/src/fish_key_reader.cpp b/src/fish_key_reader.cpp index fad5e7903..18d33a940 100644 --- a/src/fish_key_reader.cpp +++ b/src/fish_key_reader.cpp @@ -39,9 +39,10 @@ struct config_paths_t determine_config_directory_paths(const char *argv0); static const wchar_t *ctrl_symbolic_names[] = { - NULL, NULL, NULL, NULL, NULL, NULL, NULL, L"\\a", L"\\b", L"\\t", L"\\n", - L"\\v", L"\\f", L"\\r", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, L"\\e", NULL, NULL, NULL, NULL}; + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, L"\\a", + L"\\b", L"\\t", L"\\n", L"\\v", L"\\f", L"\\r", nullptr, nullptr, + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, + nullptr, nullptr, nullptr, L"\\e", nullptr, nullptr, nullptr, nullptr}; static bool keep_running = true; /// Return true if the recent sequence of characters indicates the user wants to exit the program. @@ -95,7 +96,7 @@ static maybe_t sequence_name(wchar_t wc) { /// Return true if the character must be escaped when used in the sequence of chars to be bound in /// a `bind` command. -static bool must_escape(wchar_t wc) { return std::wcschr(L"[]()<>{}*\\?$#;&|'\"", wc) != NULL; } +static bool must_escape(wchar_t wc) { return std::wcschr(L"[]()<>{}*\\?$#;&|'\"", wc) != nullptr; } static void ctrl_to_symbol(wchar_t *buf, int buf_len, wchar_t wc, bool bind_friendly) { if (ctrl_symbolic_names[wc]) { @@ -344,15 +345,15 @@ static bool parse_debug_frames_flag() { static bool parse_flags(int argc, char **argv, bool *continuous_mode) { const char *short_opts = "+cd:D:hv"; - const struct option long_opts[] = {{"continuous", no_argument, NULL, 'c'}, - {"debug-level", required_argument, NULL, 'd'}, - {"debug-stack-frames", required_argument, NULL, 'D'}, - {"help", no_argument, NULL, 'h'}, - {"version", no_argument, NULL, 'v'}, - {NULL, 0, NULL, 0}}; + const struct option long_opts[] = {{"continuous", no_argument, nullptr, 'c'}, + {"debug-level", required_argument, nullptr, 'd'}, + {"debug-stack-frames", required_argument, nullptr, 'D'}, + {"help", no_argument, nullptr, 'h'}, + {"version", no_argument, nullptr, 'v'}, + {nullptr, 0, nullptr, 0}}; int opt; bool error = false; - while (!error && (opt = getopt_long(argc, argv, short_opts, long_opts, NULL)) != -1) { + while (!error && (opt = getopt_long(argc, argv, short_opts, long_opts, nullptr)) != -1) { switch (opt) { case 'c': { *continuous_mode = true; diff --git a/src/function.cpp b/src/function.cpp index 62b8d75ec..f659239e0 100644 --- a/src/function.cpp +++ b/src/function.cpp @@ -287,7 +287,7 @@ wcstring_list_t function_get_names(int get_hidden) { const wchar_t *function_get_definition_file(const wcstring &name) { const auto funcset = function_set.acquire(); const function_info_t *func = funcset->get_info(name); - return func ? func->definition_file : NULL; + return func ? func->definition_file : nullptr; } bool function_is_autoloaded(const wcstring &name) { diff --git a/src/highlight.cpp b/src/highlight.cpp index 13e85386d..c9375fb28 100644 --- a/src/highlight.cpp +++ b/src/highlight.cpp @@ -269,7 +269,7 @@ bool is_potential_path(const wcstring &potential_path_fragment, const wcstring_l } } else { // We do not end with a slash; it does not have to be a directory. - DIR *dir = NULL; + DIR *dir = nullptr; const wcstring dir_name = wdirname(abs_path); const wcstring filename_fragment = wbasename(abs_path); if (dir_name == L"/" && filename_fragment == L"/") { @@ -287,7 +287,7 @@ bool is_potential_path(const wcstring &potential_path_fragment, const wcstring_l // access. wcstring ent; bool is_dir = false; - while (wreaddir_resolving(dir, dir_name, ent, require_dir ? &is_dir : NULL)) { + while (wreaddir_resolving(dir, dir_name, ent, require_dir ? &is_dir : nullptr)) { // Maybe skip directories. if (require_dir && !is_dir) { continue; @@ -403,7 +403,7 @@ static bool autosuggest_parse_command(const wcstring &buff, const environment_t parse_node_tree_t parse_tree; parse_tree_from_string(buff, parse_flag_continue_after_error | parse_flag_accept_incomplete_tokens, - &parse_tree, NULL); + &parse_tree, nullptr); // Find the first statement. tnode_t first_statement{}; @@ -459,7 +459,7 @@ bool autosuggest_validate_from_history(const history_item_t &item, // Not handled specially so handle it here. bool cmd_ok = false; - if (path_get_path(parsed_command, NULL, vars)) { + if (path_get_path(parsed_command, nullptr, vars)) { cmd_ok = true; } else if (builtin_exists(parsed_command) || function_exists_no_autoload(parsed_command)) { cmd_ok = true; @@ -503,7 +503,7 @@ static size_t color_variable(const wchar_t *in, size_t in_len, // Handle a slice, up to dollar_count of them. Note that we currently don't do any validation of // the slice's contents, e.g. $foo[blah] will not show an error even though it's invalid. for (size_t slice_count = 0; slice_count < dollar_count && in[idx] == L'['; slice_count++) { - wchar_t *slice_begin = NULL, *slice_end = NULL; + wchar_t *slice_begin = nullptr, *slice_end = nullptr; int located = parse_util_locate_slice(in + idx, &slice_begin, &slice_end, false); if (located == 1) { size_t slice_begin_idx = slice_begin - in, slice_end_idx = slice_end - in; @@ -813,7 +813,7 @@ class highlighter_t { parse_tree_from_string(buff, parse_flag_continue_after_error | parse_flag_include_comments | parse_flag_accept_incomplete_tokens, - &this->parse_tree, NULL); + &this->parse_tree, nullptr); } // Perform highlighting, returning an array of colors. @@ -975,7 +975,7 @@ void highlighter_t::color_redirection(tnode_t redirection_node) // Check if the argument contains a command substitution. If so, highlight it as a param // even though it's a command redirection, and don't try to do any other validation. - if (parse_util_locate_cmdsubst(target.c_str(), NULL, NULL, true) != 0) { + if (parse_util_locate_cmdsubst(target.c_str(), nullptr, nullptr, true) != 0) { this->color_argument(redir_target); } else { // No command substitution, so we can highlight the target file or fd. For example, @@ -1087,7 +1087,7 @@ void highlighter_t::color_children(const parse_node_t &parent, parse_token_type_ highlight_spec_t color) { for (node_offset_t idx = 0; idx < parent.child_count; idx++) { const parse_node_t *child = this->parse_tree.get_child(parent, idx); - if (child != NULL && child->type == type) { + if (child != nullptr && child->type == type) { this->color_node(*child, color); } } @@ -1127,7 +1127,7 @@ static bool command_is_valid(const wcstring &cmd, enum parse_statement_decoratio if (!is_valid && abbreviation_ok) is_valid = expand_abbreviation(cmd, vars).has_value(); // Regular commands - if (!is_valid && command_ok) is_valid = path_get_path(cmd, NULL, vars); + if (!is_valid && command_ok) is_valid = path_get_path(cmd, nullptr, vars); // Implicit cd if (!is_valid && implicit_cd_ok) { diff --git a/src/history.cpp b/src/history.cpp index f277e8d74..911d0d577 100644 --- a/src/history.cpp +++ b/src/history.cpp @@ -144,7 +144,7 @@ class history_lru_cache_t : public lru_cache_tget(key); - if (node == NULL) { + if (node == nullptr) { this->insert(std::move(key), std::move(item)); } else { node->creation_timestamp = std::max(node->timestamp(), item.timestamp()); @@ -252,7 +252,7 @@ struct history_impl_t { // the boundary are considered "old". Items whose timestemps are > the boundary are new, and are // ignored by this instance (unless they came from this instance). The timestamp may be adjusted // by incorporate_external_changes(). - time_t boundary_timestamp{time(NULL)}; + time_t boundary_timestamp{time(nullptr)}; // How many items we add until the next vacuum. Initially a random value. int countdown_to_vacuum{-1}; @@ -378,7 +378,7 @@ void history_impl_t::save_unless_disabled() { // the counter. const int kVacuumFrequency = 25; if (countdown_to_vacuum < 0) { - unsigned int seed = static_cast(time(NULL)); + unsigned int seed = static_cast(time(nullptr)); // Generate a number in the range [0, kVacuumFrequency). countdown_to_vacuum = rand_r(&seed) / (RAND_MAX / kVacuumFrequency + 1); } @@ -402,7 +402,7 @@ void history_impl_t::save_unless_disabled() { void history_impl_t::add(const wcstring &str, history_identifier_t ident, bool pending, bool do_save) { - time_t when = time(NULL); + time_t when = time(nullptr); // Big hack: do not allow timestamps equal to our boundary date. This is because we include // items whose timestamps are equal to our boundary when reading old history, so we can catch // "just closed" items. But this means that we may interpret our own items, that we just wrote, @@ -1108,7 +1108,7 @@ static bool should_import_bash_history_line(const wcstring &line) { if (line.empty()) return false; parse_node_tree_t parse_tree; - if (!parse_tree_from_string(line, parse_flag_none, &parse_tree, NULL)) return false; + if (!parse_tree_from_string(line, parse_flag_none, &parse_tree, nullptr)) return false; // In doing this test do not allow incomplete strings. Hence the "false" argument. parse_error_list_t errors; @@ -1175,7 +1175,7 @@ void history_impl_t::incorporate_external_changes() { // is somehwhat expensive because we will be going back over old items. An optimization would be // to preserve old_item_offsets so that they don't have to be recomputed. (However, then items // *deleted* in other instances would not show up here). - time_t new_timestamp = time(NULL); + time_t new_timestamp = time(nullptr); // If for some reason the clock went backwards, we don't want to start dropping items; therefore // we only do work if time has progressed. This also makes multiple calls cheap. @@ -1277,7 +1277,7 @@ void history_t::add_pending_with_file_detection(const wcstring &str, // Find all arguments that look like they could be file paths. bool needs_sync_write = false; parse_node_tree_t tree; - parse_tree_from_string(str, parse_flag_none, &tree, NULL); + parse_tree_from_string(str, parse_flag_none, &tree, nullptr); path_list_t potential_paths; for (const parse_node_t &node : tree) { diff --git a/src/history_file.cpp b/src/history_file.cpp index 97a89c9ee..0617fbc1b 100644 --- a/src/history_file.cpp +++ b/src/history_file.cpp @@ -126,14 +126,14 @@ std::unique_ptr history_file_contents_t::create(int fd) if (should_mmap(fd)) { // We feel confident to map the file directly. Note this is still risky: if another // process truncates the file we risk SIGBUS. - mmap_start = mmap(0, size_t(len), PROT_READ, MAP_PRIVATE, fd, 0); + mmap_start = mmap(nullptr, size_t(len), PROT_READ, MAP_PRIVATE, fd, 0); if (mmap_start == MAP_FAILED) return nullptr; } else { // We don't want to map the file. mmap some private memory and then read into it. We use // mmap instead of malloc so that the destructor can always munmap(). mmap_start = #ifdef MAP_ANON - mmap(0, size_t(len), PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0); + mmap(nullptr, size_t(len), PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0); #else mmap(0, size_t(len), PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); #endif @@ -184,7 +184,7 @@ static size_t read_line(const char *base, size_t cursor, size_t len, std::string assert(cursor <= len); const char *start = base + cursor; const char *a_newline = static_cast(std::memchr(start, '\n', len - cursor)); - if (a_newline != NULL) { // we found a newline + if (a_newline != nullptr) { // we found a newline result.assign(start, a_newline - start); // Return the amount to advance the cursor; skip over the newline. return a_newline - start + 1; @@ -256,7 +256,7 @@ static history_item_t decode_item_fish_2_0(const char *base, size_t len) { if (key == "when") { // Parse an int from the timestamp. Should this fail, strtol returns 0; that's // acceptable. - char *end = NULL; + char *end = nullptr; long tmp = strtol(value.c_str(), &end, 0); when = tmp; } else if (key == "paths") { @@ -302,7 +302,7 @@ static bool parse_timestamp(const char *str, time_t *out_when) { // Try to parse a timestamp. long timestamp = 0; - if (isdigit(*cursor) && (timestamp = strtol(cursor, NULL, 0)) > 0) { + if (isdigit(*cursor) && (timestamp = strtol(cursor, nullptr, 0)) > 0) { *out_when = static_cast(timestamp); return true; } @@ -313,23 +313,23 @@ static bool parse_timestamp(const char *str, time_t *out_when) { /// newline. Note that the string is not null terminated. static const char *next_line(const char *start, const char *end) { // Handle the hopeless case. - if (end == start) return NULL; + if (end == start) return nullptr; // Skip past the next newline. const char *nextline = std::find(start, end, '\n'); if (nextline == end) { - return NULL; + return nullptr; } // Skip past the newline character itself. if (++nextline >= end) { - return NULL; + return nullptr; } // Make sure this new line is itself "newline terminated". If it's not, return NULL. const char *next_newline = std::find(nextline, end, '\n'); if (next_newline == end) { - return NULL; + return nullptr; } return nextline; @@ -352,7 +352,7 @@ static size_t offset_of_next_item_fish_2_0(const history_file_contents_t &conten // Advance the cursor to the next line. const char *a_newline = static_cast(std::memchr(line_start, '\n', length - cursor)); - if (a_newline == NULL) break; + if (a_newline == nullptr) break; // Advance the cursor past this line. +1 is for the newline. cursor = a_newline - begin + 1; @@ -403,7 +403,7 @@ static size_t offset_of_next_item_fish_2_0(const history_file_contents_t &conten const char *interior_line; for (interior_line = next_line(line_start, end); - interior_line != NULL && !has_timestamp; + interior_line != nullptr && !has_timestamp; interior_line = next_line(interior_line, end)) { // If the first character is not a space, it's not an interior line, so we're done. if (interior_line[0] != ' ') break; diff --git a/src/input.cpp b/src/input.cpp index 91803b660..c98600cff 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -436,7 +436,7 @@ void inputter_t::push_front(char_event_t ch) { event_queue_.push_front(ch); } /// \return the first mapping that matches, walking first over the user's mapping list, then the /// preset list. \return null if nothing matches. maybe_t inputter_t::find_mapping() { - const input_mapping_t *generic = NULL; + const input_mapping_t *generic = nullptr; const auto &vars = parser_->vars(); const wcstring bind_mode = input_get_bind_mode(vars); @@ -553,7 +553,7 @@ std::vector input_mapping_set_t::get_names(bool user) cons void input_mapping_set_t::clear(const wchar_t *mode, bool user) { all_mappings_cache_.reset(); mapping_list_t &ml = user ? mapping_list_ : preset_mapping_list_; - auto should_erase = [=](const input_mapping_t &m) { return mode == NULL || mode == m.mode; }; + auto should_erase = [=](const input_mapping_t &m) { return mode == nullptr || mode == m.mode; }; ml.erase(std::remove_if(ml.begin(), ml.end(), should_erase), ml.end()); } diff --git a/src/input.h b/src/input.h index a58cc9e4f..63e4e4533 100644 --- a/src/input.h +++ b/src/input.h @@ -91,7 +91,7 @@ class input_mapping_set_t { ~input_mapping_set_t(); /// Erase all bindings. - void clear(const wchar_t *mode = NULL, bool user = true); + void clear(const wchar_t *mode = nullptr, bool user = true); /// Erase binding for specified key sequence. bool erase(const wcstring &sequence, const wcstring &mode = DEFAULT_BIND_MODE, diff --git a/src/input_common.cpp b/src/input_common.cpp index 29b849895..4d4b82d64 100644 --- a/src/input_common.cpp +++ b/src/input_common.cpp @@ -75,7 +75,7 @@ char_event_t input_event_queue_t::readb() { tv.tv_usec = static_cast(usecs_delay % usecs_per_sec); } - res = select(fd_max + 1, &fdset, 0, 0, usecs_delay > 0 ? &tv : NULL); + res = select(fd_max + 1, &fdset, nullptr, nullptr, usecs_delay > 0 ? &tv : nullptr); if (res == -1) { if (errno == EINTR || errno == EAGAIN) { if (interrupt_handler) { @@ -213,7 +213,7 @@ char_event_t input_event_queue_t::readch_timed(bool dequeue_timeouts) { FD_ZERO(&fds); FD_SET(STDIN_FILENO, &fds); struct timeval tm = {wait_on_escape_ms / 1000, 1000 * (wait_on_escape_ms % 1000)}; - if (select(1, &fds, 0, 0, &tm) > 0) { + if (select(1, &fds, nullptr, nullptr, &tm) > 0) { result = readch(); } } diff --git a/src/intern.cpp b/src/intern.cpp index e609dd3b6..53dc61214 100644 --- a/src/intern.cpp +++ b/src/intern.cpp @@ -19,7 +19,7 @@ bool string_less_than_string(const wchar_t *a, const wchar_t *b) { return std::w owning_lock> string_table; static const wchar_t *intern_with_dup(const wchar_t *in, bool dup) { - if (!in) return NULL; + if (!in) return nullptr; debug(5, L"intern %ls", in); auto table = string_table.acquire(); diff --git a/src/io.cpp b/src/io.cpp index ec92a9751..92f880e69 100644 --- a/src/io.cpp +++ b/src/io.cpp @@ -79,7 +79,7 @@ void io_buffer_t::run_background_fillthread(autoclose_fd_t readfd) { fd_set fds; FD_ZERO(&fds); FD_SET(fd, &fds); - int ret = select(fd + 1, &fds, NULL, NULL, &tv); + int ret = select(fd + 1, &fds, nullptr, nullptr, &tv); // select(2) is allowed to (and does) update `tv` to indicate how much time was left, so we // need to restore the desired value each time. tv.tv_usec = poll_timeout_usec; @@ -234,7 +234,7 @@ void io_print(const io_chain_t &chain) for (size_t i=0; i < chain.size(); i++) { const shared_ptr &io = chain.at(i); - if (io.get() == NULL) + if (io.get() == nullptr) { std::fwprintf(stderr, L"\t(null)\n"); } diff --git a/src/iothread.cpp b/src/iothread.cpp index e13af9900..9c784d17a 100644 --- a/src/iothread.cpp +++ b/src/iothread.cpp @@ -277,7 +277,7 @@ static bool iothread_wait_for_pending_completions(long timeout_usec) { fd_set fds; FD_ZERO(&fds); FD_SET(fd, &fds); - int ret = select(fd + 1, &fds, NULL, NULL, &tv); + int ret = select(fd + 1, &fds, nullptr, nullptr, &tv); return ret > 0; } @@ -416,7 +416,7 @@ bool make_pthread(pthread_t *result, void *(*func)(void *), void *param) { // unlikely that they are all on the verge of exiting, so one is likely to be ready to handle // extant requests. So we can ignore failure with some confidence. pthread_t thread = 0; - int err = pthread_create(&thread, NULL, func, param); + int err = pthread_create(&thread, nullptr, func, param); if (err == 0) { // Success, return the thread. debug(5, "pthread %p spawned", (void *)(intptr_t)thread); @@ -425,7 +425,7 @@ bool make_pthread(pthread_t *result, void *(*func)(void *), void *param) { perror("pthread_create"); } // Restore our sigmask. - DIE_ON_FAILURE(pthread_sigmask(SIG_SETMASK, &saved_set, NULL)); + DIE_ON_FAILURE(pthread_sigmask(SIG_SETMASK, &saved_set, nullptr)); return err == 0; } diff --git a/src/lru.h b/src/lru.h index 63fc09e52..97b19de2e 100644 --- a/src/lru.h +++ b/src/lru.h @@ -24,8 +24,8 @@ class lru_cache_t { struct lru_link_t { // Our doubly linked list // The base class is used for the mouth only - lru_link_t *prev = NULL; - lru_link_t *next = NULL; + lru_link_t *prev = nullptr; + lru_link_t *next = nullptr; }; // The node type in our LRU cache @@ -36,7 +36,7 @@ class lru_cache_t { lru_node_t(lru_node_t &&) = default; // Our key in the map. This is owned by the map itself. - const wcstring *key = NULL; + const wcstring *key = nullptr; // The value from the client Contents value; @@ -78,7 +78,7 @@ class lru_cache_t { // Remove the node void evict_node(lru_node_t *node) { // We should never evict the mouth. - assert(node != &mouth && node != NULL && node->key != NULL); + assert(node != &mouth && node != nullptr && node->key != nullptr); auto iter = this->node_map.find(*node->key); assert(iter != this->node_map.end()); @@ -188,7 +188,7 @@ class lru_cache_t { auto where = this->node_map.find(key); if (where == this->node_map.end()) { // not found - return NULL; + return nullptr; } promote_node(&where->second); return &where->second.value; diff --git a/src/output.cpp b/src/output.cpp index 5ebf1e1db..75aa8bb43 100644 --- a/src/output.cpp +++ b/src/output.cpp @@ -401,7 +401,7 @@ int outputter_t::writech(wint_t ch) { void outputter_t::writestr(const wchar_t *str) { assert(str && "Empty input string"); - size_t len = wcstombs(0, str, 0); // figure amount of space needed + size_t len = wcstombs(nullptr, str, 0); // figure amount of space needed if (len == static_cast(-1)) { debug(1, L"Tried to print invalid wide character string"); return; @@ -526,7 +526,7 @@ rgb_color_t parse_color(const env_var_t &var, bool is_background) { /// Write specified multibyte string. void writembs_check(outputter_t &outp, const char *mbs, const char *mbs_name, bool critical, const char *file, long line) { - if (mbs != NULL) { + if (mbs != nullptr) { outp.term_puts(mbs, 1); } else if (critical) { auto term = env_stack_t::globals().get(L"TERM"); diff --git a/src/pager.cpp b/src/pager.cpp index dd66e8b60..d36a908e6 100644 --- a/src/pager.cpp +++ b/src/pager.cpp @@ -809,7 +809,7 @@ bool pager_t::is_navigating_contents() const { void pager_t::set_fully_disclosed(bool flag) { fully_disclosed = flag; } const completion_t *pager_t::selected_completion(const page_rendering_t &rendering) const { - const completion_t *result = NULL; + const completion_t *result = nullptr; size_t idx = visual_selected_completion_index(rendering.rows, rendering.cols); if (idx != PAGER_SELECTION_NONE) { result = &completion_infos.at(idx).representative; diff --git a/src/parse_constants.h b/src/parse_constants.h index 902ba92a0..8f116b441 100644 --- a/src/parse_constants.h +++ b/src/parse_constants.h @@ -92,7 +92,7 @@ const enum_map token_enum_map[] = { #define ELEM(sym) {symbol_##sym, L"symbol_" #sym}, #include "parse_grammar_elements.inc" {token_type_invalid, L"token_type_invalid"}, - {token_type_invalid, NULL}}; + {token_type_invalid, nullptr}}; #define token_enum_map_len (sizeof token_enum_map / sizeof *token_enum_map) // IMPORTANT: If the following enum is modified you must update the corresponding keyword_enum_map @@ -137,7 +137,7 @@ const enum_map keyword_enum_map[] = {{parse_keyword_exclam, L"! {parse_keyword_or, L"or"}, {parse_keyword_switch, L"switch"}, {parse_keyword_while, L"while"}, - {parse_keyword_none, NULL}}; + {parse_keyword_none, nullptr}}; #define keyword_enum_map_len (sizeof keyword_enum_map / sizeof *keyword_enum_map) // Node tag values. diff --git a/src/parse_execution.cpp b/src/parse_execution.cpp index 908317faf..3ecffee42 100644 --- a/src/parse_execution.cpp +++ b/src/parse_execution.cpp @@ -138,7 +138,7 @@ tnode_t parse_execution_context_t::infinite_recursive_statem cmd == forbidden_function_name) { // This is it. infinite_recursive_statement = plain_statement; - if (out_func_name != NULL) { + if (out_func_name != nullptr) { *out_func_name = forbidden_function_name; } break; @@ -783,8 +783,8 @@ parse_execution_result_t parse_execution_context_t::expand_command( /// Creates a 'normal' (non-block) process. parse_execution_result_t parse_execution_context_t::populate_plain_process( job_t *job, process_t *proc, tnode_t statement) { - assert(job != NULL); - assert(proc != NULL); + assert(job != nullptr); + assert(proc != nullptr); // We may decide that a command should be an implicit cd. bool use_implicit_cd = false; @@ -1009,7 +1009,7 @@ bool parse_execution_context_t::determine_io_chain(tnode_t jo // Profiling support. long long start_time = 0, parse_time = 0, exec_time = 0; profile_item_t *profile_item = this->parser->create_profile_item(); - if (profile_item != NULL) { + if (profile_item != nullptr) { start_time = get_time(); } @@ -1303,7 +1303,7 @@ parse_execution_result_t parse_execution_context_t::run_1_job(tnode_t jo } } - if (profile_item != NULL) { + if (profile_item != nullptr) { // Block-types profile a little weird. They have no 'parse' time, and their command is // just the block type. exec_time = get_time(); @@ -1353,7 +1353,7 @@ parse_execution_result_t parse_execution_context_t::run_1_job(tnode_t jo parser->libdata().caller_job_id = saved_caller_jid; // Store time it took to 'parse' the command. - if (profile_item != NULL) { + if (profile_item != nullptr) { parse_time = get_time(); } @@ -1384,7 +1384,7 @@ parse_execution_result_t parse_execution_context_t::run_1_job(tnode_t jo } } - if (profile_item != NULL) { + if (profile_item != nullptr) { exec_time = get_time(); profile_item->level = parser->eval_level; profile_item->parse = static_cast(parse_time - start_time); diff --git a/src/parse_productions.cpp b/src/parse_productions.cpp index 99cf0ffba..41acc802b 100644 --- a/src/parse_productions.cpp +++ b/src/parse_productions.cpp @@ -13,7 +13,7 @@ using namespace parse_productions; using namespace grammar; -#define NO_PRODUCTION NULL +#define NO_PRODUCTION nullptr // Herein are encoded the productions for our LL2 fish grammar. // @@ -408,7 +408,7 @@ const production_element_t *parse_productions::production_for_token(parse_token_ const production_element_t *(*resolver)(const parse_token_t &input1, //!OCLINT(unused param) const parse_token_t &input2, //!OCLINT(unused param) parse_node_tag_t *out_tag) = //!OCLINT(unused param) - NULL; + nullptr; switch (node_type) { // Handle all of our grammar elements #define ELEM(SYM) \ @@ -445,10 +445,10 @@ const production_element_t *parse_productions::production_for_token(parse_token_ break; } } - PARSE_ASSERT(resolver != NULL); + PARSE_ASSERT(resolver != nullptr); const production_element_t *result = resolver(input1, input2, out_tag); - if (result == NULL) { + if (result == nullptr) { debug(5, L"Node type '%ls' has no production for input '%ls' (in %s)", token_type_description(node_type), input1.describe().c_str(), __FUNCTION__); } diff --git a/src/parse_tree.cpp b/src/parse_tree.cpp index a47d6fe3b..ef2747c76 100644 --- a/src/parse_tree.cpp +++ b/src/parse_tree.cpp @@ -124,7 +124,7 @@ wcstring parse_error_t::describe(const wcstring &src, bool is_interactive) const } void parse_error_offset_source_start(parse_error_list_t *errors, size_t amt) { - assert(errors != NULL); + assert(errors != nullptr); if (amt > 0) { size_t i, max = errors->size(); for (i = 0; i < max; i++) { @@ -593,10 +593,10 @@ void parse_ll_t::determine_node_ranges() { } void parse_ll_t::acquire_output(parse_node_tree_t *output, parse_error_list_t *errors) { - if (output != NULL) { + if (output != nullptr) { *output = std::move(this->nodes); } - if (errors != NULL) { + if (errors != nullptr) { *errors = std::move(this->errors); } } @@ -752,14 +752,14 @@ bool parse_ll_t::report_error_for_unclosed_block() { // switch_statement, etc., each with different node structures. But keep descending the first // child and eventually you hit a keyword: begin, if, etc. That's the keyword we care about. const parse_node_t *end_command = this->nodes.get_parent(top_node, symbol_end_command); - const parse_node_t *block_node = end_command ? this->nodes.get_parent(*end_command) : NULL; + const parse_node_t *block_node = end_command ? this->nodes.get_parent(*end_command) : nullptr; if (block_node && block_node->type == symbol_block_statement) { // Get the header. block_node = this->nodes.get_child(*block_node, 0, symbol_block_header); block_node = this->nodes.get_child(*block_node, 0); // specific statement } - if (block_node == NULL) { + if (block_node == nullptr) { return reported_error; } @@ -773,7 +773,7 @@ bool parse_ll_t::report_error_for_unclosed_block() { const parse_node_t *cursor = block_node; while (cursor->child_count > 0) { cursor = this->nodes.get_child(*cursor, 0); - assert(cursor != NULL); + assert(cursor != nullptr); } if (cursor->source_start != NODE_OFFSET_INVALID) { const wcstring node_desc = block_type_user_presentable_description(block_node->type); @@ -917,7 +917,7 @@ void parse_ll_t::accept_tokens(parse_token_t token1, parse_token_t token2) { const production_element_t *production = production_for_token(stack_elem.type, token1, token2, &tag); node.tag = tag; - if (production == NULL) { + if (production == nullptr) { parse_error_failed_production(stack_elem, token1); // The above sets fatal_errored, which ends the loop. } else { @@ -1066,7 +1066,7 @@ bool parse_tree_from_string(const wcstring &str, parse_tree_flags_t parse_flags, parse_node_tree_t *output, parse_error_list_t *errors, parse_token_type_t goal) { parse_ll_t parser(goal); - parser.set_should_generate_error_messages(errors != NULL); + parser.set_should_generate_error_messages(errors != nullptr); // A string whose storage we reuse. wcstring storage; @@ -1147,7 +1147,7 @@ bool parse_tree_from_string(const wcstring &str, parse_tree_flags_t parse_flags, const parse_node_t *parse_node_tree_t::get_child(const parse_node_t &parent, node_offset_t which, parse_token_type_t expected_type) const { - const parse_node_t *result = NULL; + const parse_node_t *result = nullptr; // We may get nodes with no children if we had an incomplete parse. Don't consider than an // error. @@ -1185,7 +1185,7 @@ const parse_node_t &parse_node_tree_t::find_child(const parse_node_t &parent, const parse_node_t *parse_node_tree_t::get_parent(const parse_node_t &node, parse_token_type_t expected_type) const { - const parse_node_t *result = NULL; + const parse_node_t *result = nullptr; if (node.parent != NODE_OFFSET_INVALID) { PARSE_ASSERT(node.parent < this->size()); const parse_node_t &parent = this->at(node.parent); @@ -1213,10 +1213,10 @@ static bool node_has_ancestor(const parse_node_tree_t &tree, const parse_node_t const parse_node_t *parse_node_tree_t::find_node_matching_source_location( parse_token_type_t type, size_t source_loc, const parse_node_t *parent) const { - const parse_node_t *result = NULL; + const parse_node_t *result = nullptr; // Find nodes of the given type in the tree, working backwards. const size_t len = this->size(); - for (size_t idx = 0; idx < len && result == NULL; idx++) { + for (size_t idx = 0; idx < len && result == nullptr; idx++) { const parse_node_t &node = this->at(idx); // Types must match. @@ -1226,7 +1226,7 @@ const parse_node_t *parse_node_tree_t::find_node_matching_source_location( if (!node.location_in_or_at_end_of_source_range(source_loc)) continue; // If a parent is given, it must be an ancestor. - if (parent != NULL && !node_has_ancestor(*this, node, *parent)) continue; + if (parent != nullptr && !node_has_ancestor(*this, node, *parent)) continue; // Found it. result = &node; diff --git a/src/parse_util.cpp b/src/parse_util.cpp index 027d8c834..72edf9457 100644 --- a/src/parse_util.cpp +++ b/src/parse_util.cpp @@ -116,7 +116,7 @@ static int parse_util_locate_brackets_of_type(const wchar_t *in, wchar_t **begin int syntax_error = 0; int paran_count = 0; - wchar_t *paran_begin = 0, *paran_end = 0; + wchar_t *paran_begin = nullptr, *paran_end = nullptr; assert(in && "null parameter"); @@ -131,7 +131,7 @@ static int parse_util_locate_brackets_of_type(const wchar_t *in, wchar_t **begin } } else { if (*pos == open_type) { - if ((paran_count == 0) && (paran_begin == 0)) { + if ((paran_count == 0) && (paran_begin == nullptr)) { paran_begin = pos; } @@ -139,7 +139,7 @@ static int parse_util_locate_brackets_of_type(const wchar_t *in, wchar_t **begin } else if (*pos == close_type) { paran_count--; - if ((paran_count == 0) && (paran_end == 0)) { + if ((paran_count == 0) && (paran_end == nullptr)) { paran_end = pos; break; } @@ -161,7 +161,7 @@ static int parse_util_locate_brackets_of_type(const wchar_t *in, wchar_t **begin return -1; } - if (paran_begin == 0) { + if (paran_begin == nullptr) { return 0; } @@ -202,7 +202,7 @@ static int parse_util_locate_brackets_range(const wcstring &str, size_t *inout_c const wchar_t *const buff = str.c_str(); const wchar_t *const valid_range_start = buff + *inout_cursor_offset, *valid_range_end = buff + str.size(); - wchar_t *bracket_range_begin = NULL, *bracket_range_end = NULL; + wchar_t *bracket_range_begin = nullptr, *bracket_range_end = nullptr; int ret = parse_util_locate_brackets_of_type(valid_range_start, &bracket_range_begin, &bracket_range_end, accept_incomplete, open_type, close_type); @@ -212,9 +212,9 @@ static int parse_util_locate_brackets_range(const wcstring &str, size_t *inout_c // The command substitutions must not be NULL and must be in the valid pointer range, and // the end must be bigger than the beginning. - assert(bracket_range_begin != NULL && bracket_range_begin >= valid_range_start && + assert(bracket_range_begin != nullptr && bracket_range_begin >= valid_range_start && bracket_range_begin <= valid_range_end); - assert(bracket_range_end != NULL && bracket_range_end > bracket_range_begin && + assert(bracket_range_end != nullptr && bracket_range_end > bracket_range_begin && bracket_range_end >= valid_range_start && bracket_range_end <= valid_range_end); // Assign the substring to the out_contents. @@ -252,13 +252,13 @@ void parse_util_cmdsubst_extent(const wchar_t *buff, size_t cursor_pos, const wc const wchar_t *ap = buff, *bp = buff + bufflen; const wchar_t *pos = buff; for (;;) { - wchar_t *begin = NULL, *end = NULL; + wchar_t *begin = nullptr, *end = nullptr; if (parse_util_locate_cmdsubst(pos, &begin, &end, true) <= 0) { // No subshell found, all done. break; } // Interpret NULL to mean the end. - if (end == NULL) { + if (end == nullptr) { end = const_cast(buff) + bufflen; } @@ -283,8 +283,8 @@ void parse_util_cmdsubst_extent(const wchar_t *buff, size_t cursor_pos, const wc } } - if (a != NULL) *a = ap; - if (b != NULL) *b = bp; + if (a != nullptr) *a = ap; + if (b != nullptr) *b = bp; } /// Get the beginning and end of the job or process definition under the cursor. @@ -357,7 +357,7 @@ void parse_util_token_extent(const wchar_t *buff, size_t cursor_pos, const wchar const wchar_t **tok_end, const wchar_t **prev_begin, const wchar_t **prev_end) { assert(buff && "Null buffer"); - const wchar_t *a = NULL, *b = NULL, *pa = NULL, *pb = NULL; + const wchar_t *a = nullptr, *b = nullptr, *pa = nullptr, *pb = nullptr; const wchar_t *cmdsubst_begin, *cmdsubst_end; parse_util_cmdsubst_extent(buff, cursor_pos, &cmdsubst_begin, &cmdsubst_end); @@ -471,7 +471,7 @@ static wchar_t get_quote(const wcstring &cmd_str, size_t len) { if (cmd[i] == L'\'' || cmd[i] == L'\"') { const wchar_t *end = quote_end(&cmd[i]); // std::fwprintf( stderr, L"Jump %d\n", end-cmd ); - if ((end == 0) || (!*end) || (end > cmd + len)) { + if ((end == nullptr) || (!*end) || (end > cmd + len)) { res = cmd[i]; break; } @@ -496,7 +496,7 @@ void parse_util_get_parameter_info(const wcstring &cmd, const size_t pos, wchar_ if (token->type == token_type_t::string) last_quote = get_quote(tok.text_of(*token), pos - token->offset); - if (out_type != NULL) *out_type = token->type; + if (out_type != nullptr) *out_type = token->type; prev_pos = token->offset; } @@ -506,7 +506,7 @@ void parse_util_get_parameter_info(const wcstring &cmd, const size_t pos, wchar_ size_t cmdlen = pos; bool finished = cmdlen != 0; if (finished) { - finished = (quote == NULL); + finished = (quote == nullptr); if (finished && std::wcschr(L" \t\n\r", cmd_tmp[cmdlen - 1])) { finished = cmdlen > 1 && cmd_tmp[cmdlen - 2] == L'\\'; } @@ -514,9 +514,9 @@ void parse_util_get_parameter_info(const wcstring &cmd, const size_t pos, wchar_ if (quote) *quote = last_quote; - if (offset != 0) { + if (offset != nullptr) { if (finished) { - while ((cmd_tmp[prev_pos] != 0) && (std::wcschr(L";|", cmd_tmp[prev_pos]) != 0)) + while ((cmd_tmp[prev_pos] != 0) && (std::wcschr(L";|", cmd_tmp[prev_pos]) != nullptr)) prev_pos++; *offset = prev_pos; } else { @@ -688,7 +688,7 @@ std::vector parse_util_compute_indents(const wcstring &src) { parse_tree_from_string(src, parse_flag_continue_after_error | parse_flag_include_comments | parse_flag_accept_incomplete_tokens, - &tree, NULL /* errors */); + &tree, nullptr /* errors */); // Start indenting at the first node. If we have a parse error, we'll have to start indenting // from the top again. @@ -832,7 +832,7 @@ void parse_util_expand_variable_error(const wcstring &token, size_t global_token size_t dollar_pos, parse_error_list_t *errors) { // Note that dollar_pos is probably VARIABLE_EXPAND or VARIABLE_EXPAND_SINGLE, not a literal // dollar sign. - assert(errors != NULL); + assert(errors != nullptr); assert(dollar_pos < token.size()); const bool double_quotes = token.at(dollar_pos) == VARIABLE_EXPAND_SINGLE; const size_t start_error_count = errors->size(); @@ -934,7 +934,7 @@ static parser_test_error_bits_t detect_dollar_cmdsub_errors(size_t arg_src_offse wchar_t last = unescaped_arg_src.at(unescaped_arg_src.size() - 1); if (last == VARIABLE_EXPAND) { result_bits |= PARSER_TEST_ERROR; - if (out_errors != NULL) { + if (out_errors != nullptr) { wcstring subcommand_first_token = tok_first(cmdsubst_src); if (subcommand_first_token.empty()) { // e.g. $(). Report somthing. @@ -995,7 +995,7 @@ parser_test_error_bits_t parse_util_detect_errors_in_argument(tnode_tinsert(out_errors->end(), subst_errors.begin(), subst_errors.end()); // Hackish. Take this opportunity to report $(...) errors. We do this because @@ -1319,11 +1319,11 @@ parser_test_error_bits_t parse_util_detect_errors(const wcstring &buff_src, if (has_unclosed_block || has_unclosed_quote_or_subshell || has_unclosed_pipe) res |= PARSER_TEST_INCOMPLETE; - if (out_errors != NULL) { + if (out_errors != nullptr) { *out_errors = std::move(parse_errors); } - if (out_pstree != NULL) { + if (out_pstree != nullptr) { *out_pstree = std::make_shared(buff_src, std::move(node_tree)); } diff --git a/src/parse_util.h b/src/parse_util.h index 49458eed0..d7857b742 100644 --- a/src/parse_util.h +++ b/src/parse_util.h @@ -129,9 +129,9 @@ std::vector parse_util_compute_indents(const wcstring &src); /// error. If out_pstree is not NULL, the resulting tree is returned by reference. class parse_node_tree_t; parser_test_error_bits_t parse_util_detect_errors(const wcstring &buff_src, - parse_error_list_t *out_errors = NULL, + parse_error_list_t *out_errors = nullptr, bool allow_incomplete = true, - parsed_source_ref_t *out_pstree = NULL); + parsed_source_ref_t *out_pstree = nullptr); /// Detect errors in the specified string when parsed as an argument list. Returns the text of an /// error, or none if no error occurred. @@ -144,7 +144,7 @@ maybe_t parse_util_detect_errors_in_argument_list(const wcstring &arg_ class parse_node_t; parser_test_error_bits_t parse_util_detect_errors_in_argument( tnode_t node, const wcstring &arg_src, - parse_error_list_t *out_errors = NULL); + parse_error_list_t *out_errors = nullptr); /// Given a string containing a variable expansion error, append an appropriate error to the errors /// list. The global_token_pos is the offset of the token in the larger source, and the dollar_pos diff --git a/src/parser.cpp b/src/parser.cpp index 1c118d92e..7e19cb065 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -89,17 +89,17 @@ static const struct block_lookup_entry block_lookup[] = { {WHILE, L"while", WHILE_BLOCK}, {FOR, L"for", FOR_BLOCK}, {IF, L"if", IF_BLOCK}, - {FUNCTION_CALL, 0, FUNCTION_CALL_BLOCK}, - {FUNCTION_CALL_NO_SHADOW, 0, FUNCTION_CALL_NO_SHADOW_BLOCK}, + {FUNCTION_CALL, nullptr, FUNCTION_CALL_BLOCK}, + {FUNCTION_CALL_NO_SHADOW, nullptr, FUNCTION_CALL_NO_SHADOW_BLOCK}, {SWITCH, L"switch", SWITCH_BLOCK}, - {TOP, 0, TOP_BLOCK}, - {SUBST, 0, SUBST_BLOCK}, + {TOP, nullptr, TOP_BLOCK}, + {SUBST, nullptr, SUBST_BLOCK}, {BEGIN, L"begin", BEGIN_BLOCK}, {SOURCE, L"source", SOURCE_BLOCK}, - {EVENT, 0, EVENT_BLOCK}, + {EVENT, nullptr, EVENT_BLOCK}, {BREAKPOINT, L"breakpoint", BREAKPOINT_BLOCK}, {VARIABLE_ASSIGNMENT, L"variable assignment", VARIABLE_ASSIGNMENT_BLOCK}, - {static_cast(0), 0, 0}}; + {static_cast(0), nullptr, nullptr}}; // Given a file path, return something nicer. Currently we just "unexpand" tildes. wcstring parser_t::user_presentable_path(const wcstring &path) const { @@ -141,7 +141,7 @@ block_t *parser_t::push_block(block_t &&block) { new_current.src_lineno = parser_t::get_lineno(); const wchar_t *filename = parser_t::current_filename(); - if (filename != NULL) { + if (filename != nullptr) { new_current.src_filename = intern(filename); } @@ -234,15 +234,15 @@ wcstring parser_t::block_stack_description() const { const block_t *parser_t::block_at_index(size_t idx) const { // Zero corresponds to the last element in our vector. size_t count = block_stack.size(); - return idx < count ? &block_stack.at(count - idx - 1) : NULL; + return idx < count ? &block_stack.at(count - idx - 1) : nullptr; } block_t *parser_t::block_at_index(size_t idx) { size_t count = block_stack.size(); - return idx < count ? &block_stack.at(count - idx - 1) : NULL; + return idx < count ? &block_stack.at(count - idx - 1) : nullptr; } -block_t *parser_t::current_block() { return block_stack.empty() ? NULL : &block_stack.back(); } +block_t *parser_t::current_block() { return block_stack.empty() ? nullptr : &block_stack.back(); } /// Print profiling information to the specified stream. static void print_profile(const std::vector> &items, FILE *out) { @@ -320,7 +320,7 @@ std::vector parser_t::expand_argument_list(const wcstring &arg_lis const std::shared_ptr &parser) { // Parse the string as an argument list. parse_node_tree_t tree; - if (!parse_tree_from_string(arg_list_src, parse_flag_none, &tree, NULL /* errors */, + if (!parse_tree_from_string(arg_list_src, parse_flag_none, &tree, nullptr /* errors */, symbol_freestanding_argument_list)) { // Failed to parse. Here we expect to have reported any errors in test_args. return {}; @@ -332,7 +332,7 @@ std::vector parser_t::expand_argument_list(const wcstring &arg_lis tnode_t arg_list(&tree, &tree.at(0)); while (auto arg = arg_list.next_in_list()) { const wcstring arg_src = arg.get_source(arg_list_src); - if (expand_string(arg_src, &result, eflags, vars, parser, NULL /* errors */) == + if (expand_string(arg_src, &result, eflags, vars, parser, nullptr /* errors */) == expand_result_t::error) { break; // failed to expand a string } @@ -434,7 +434,7 @@ const wchar_t *parser_t::is_function(size_t idx) const { // PCA: Have to make this a string somehow. ASSERT_IS_MAIN_THREAD(); - const wchar_t *result = NULL; + const wchar_t *result = nullptr; for (size_t block_idx = idx; block_idx < this->block_count(); block_idx++) { const block_t *b = this->block_at_index(block_idx); if (b->type() == FUNCTION_CALL || b->type() == FUNCTION_CALL_NO_SHADOW) { @@ -462,7 +462,7 @@ const wchar_t *parser_t::get_function_name(int level) { } idx++; } - return NULL; // couldn't find a breakpoint frame + return nullptr; // couldn't find a breakpoint frame } else if (level == 1) { // Return the function name for the current level. return this->is_function(); @@ -477,7 +477,7 @@ const wchar_t *parser_t::get_function_name(int level) { } idx++; } - return NULL; // couldn't find that function level + return nullptr; // couldn't find that function level } int parser_t::get_lineno() const { @@ -487,7 +487,7 @@ int parser_t::get_lineno() const { // If we are executing a function, we have to add in its offset. const wchar_t *function_name = is_function(); - if (function_name != NULL) { + if (function_name != nullptr) { lineno += function_get_definition_lineno(function_name); } } @@ -569,7 +569,7 @@ wcstring parser_t::current_line() { } void parser_t::job_add(shared_ptr job) { - assert(job != NULL); + assert(job != nullptr); assert(!job->processes.empty()); job_list.push_front(std::move(job)); } @@ -591,14 +591,14 @@ job_t *parser_t::job_get(job_id_t id) { for (const auto &job : job_list) { if (id <= 0 || job->job_id == id) return job.get(); } - return NULL; + return nullptr; } job_t *parser_t::job_get_from_pid(pid_t pid) const { pid_t pgid = getpgid(pid); if (pgid == -1) { - return 0; + return nullptr; } for (const auto &job : jobs()) { @@ -610,7 +610,7 @@ job_t *parser_t::job_get_from_pid(pid_t pid) const { } } } - return 0; + return nullptr; } profile_item_t *parser_t::create_profile_item() { @@ -802,7 +802,7 @@ wcstring block_t::description() const { if (this->src_lineno >= 0) { append_format(result, L" (line %d)", this->src_lineno); } - if (this->src_filename != NULL) { + if (this->src_filename != nullptr) { append_format(result, L" (file %ls)", this->src_filename); } return result; diff --git a/src/postfork.cpp b/src/postfork.cpp index 680625bf1..e1080e47d 100644 --- a/src/postfork.cpp +++ b/src/postfork.cpp @@ -199,7 +199,7 @@ pid_t execute_fork() { // Don't sleep on the final lap - sleeping might change the value of errno, which will break // the error reporting below. if (i != FORK_LAPS - 1) { - nanosleep(&pollint, NULL); + nanosleep(&pollint, nullptr); } } diff --git a/src/proc.cpp b/src/proc.cpp index 05ecf8646..d61c5bed7 100644 --- a/src/proc.cpp +++ b/src/proc.cpp @@ -262,7 +262,7 @@ static void handle_child_status(process_t *proc, proc_status_t status) { sigemptyset(&act.sa_mask); act.sa_flags = 0; act.sa_handler = SIG_DFL; - sigaction(sig, &act, 0); + sigaction(sig, &act, nullptr); kill(getpid(), sig); } } @@ -560,7 +560,7 @@ static bool process_clean_after_marking(parser_t &parser, bool allow_interactive // This may be invoked in an exit handler, after the TERM has been torn down // Don't try to print in that case (#3222) - const bool interactive = allow_interactive && cur_term != NULL; + const bool interactive = allow_interactive && cur_term != nullptr; // Remove all disowned jobs. remove_disowned_jobs(parser.jobs()); @@ -686,7 +686,7 @@ unsigned long proc_get_jiffies(process_t *p) { void proc_update_jiffies(parser_t &parser) { for (const auto &job : parser.jobs()) { for (process_ptr_t &p : job->processes) { - gettimeofday(&p->last_time, 0); + gettimeofday(&p->last_time, nullptr); p->last_jiffies = proc_get_jiffies(p.get()); } } @@ -923,7 +923,7 @@ void job_t::continue_job(parser_t &parser, bool reclaim_foreground_pgrp, bool se } void proc_sanity_check(const parser_t &parser) { - const job_t *fg_job = NULL; + const job_t *fg_job = nullptr; for (const auto &j : parser.jobs()) { if (!j->is_constructed()) continue; diff --git a/src/proc.h b/src/proc.h index 16dabfbad..6a627b26c 100644 --- a/src/proc.h +++ b/src/proc.h @@ -210,14 +210,14 @@ class process_t { /// Returns argv[idx]. const wchar_t *argv(size_t idx) const { const wchar_t *const *argv = argv_array.get(); - assert(argv != NULL); + assert(argv != nullptr); return argv[idx]; } /// Returns argv[0], or NULL. const wchar_t *argv0() const { const wchar_t *const *argv = argv_array.get(); - return argv ? argv[0] : NULL; + return argv ? argv[0] : nullptr; } /// IO chain getter and setter. diff --git a/src/reader.cpp b/src/reader.cpp index 397a5520c..4b4157eec 100644 --- a/src/reader.cpp +++ b/src/reader.cpp @@ -566,8 +566,8 @@ wcstring combine_command_and_autosuggestion(const wcstring &cmdline, } else { // We have an autosuggestion which is not a prefix of the command line, i.e. a case // disagreement. Decide whose case we want to use. - const wchar_t *begin = NULL, *cmd = cmdline.c_str(); - parse_util_token_extent(cmd, cmdline.size() - 1, &begin, NULL, NULL, NULL); + const wchar_t *begin = nullptr, *cmd = cmdline.c_str(); + parse_util_token_extent(cmd, cmdline.size() - 1, &begin, nullptr, nullptr, nullptr); bool last_token_contains_uppercase = false; if (begin) { const wchar_t *end = begin + std::wcslen(begin); @@ -720,7 +720,7 @@ void reader_data_t::pager_selection_changed() { size_t cursor_pos = this->cycle_cursor_pos; wcstring new_cmd_line; - if (completion == NULL) { + if (completion == nullptr) { new_cmd_line = this->cycle_command_line; } else { new_cmd_line = @@ -739,10 +739,10 @@ maybe_t reader_expand_abbreviation_in_command(const wcstring &cmdline, // See if we are at "command position". Get the surrounding command substitution, and get the // extent of the first token. const wchar_t *const buff = cmdline.c_str(); - const wchar_t *cmdsub_begin = NULL, *cmdsub_end = NULL; + const wchar_t *cmdsub_begin = nullptr, *cmdsub_end = nullptr; parse_util_cmdsubst_extent(buff, cursor_pos, &cmdsub_begin, &cmdsub_end); - assert(cmdsub_begin != NULL && cmdsub_begin >= buff); - assert(cmdsub_end != NULL && cmdsub_end >= cmdsub_begin); + assert(cmdsub_begin != nullptr && cmdsub_begin >= buff); + assert(cmdsub_end != nullptr && cmdsub_end >= cmdsub_begin); // Determine the offset of this command substitution. const size_t subcmd_offset = cmdsub_begin - buff; @@ -754,7 +754,7 @@ maybe_t reader_expand_abbreviation_in_command(const wcstring &cmdline, parse_node_tree_t parse_tree; parse_tree_from_string(subcmd, parse_flag_continue_after_error | parse_flag_accept_incomplete_tokens, - &parse_tree, NULL); + &parse_tree, nullptr); // Look for plain statements where the cursor is at the end of the command. using namespace grammar; @@ -1168,7 +1168,7 @@ wcstring completion_apply_to_command_line(const wcstring &val, complete_flags_t const wchar_t *begin, *end; const wchar_t *buff = command_line.c_str(); - parse_util_token_extent(buff, cursor_pos, &begin, 0, 0, 0); + parse_util_token_extent(buff, cursor_pos, &begin, nullptr, nullptr, nullptr); end = buff + cursor_pos; wcstring sb(buff, begin - buff); @@ -1208,7 +1208,7 @@ wcstring completion_apply_to_command_line(const wcstring &val, complete_flags_t // substitution as one token. parse_util_get_parameter_info( command_line.substr(cmdsub_offset, (cmdsub_end - cmdsub_begin)), - cursor_pos - cmdsub_offset, "e, NULL, NULL); + cursor_pos - cmdsub_offset, "e, nullptr, nullptr); // If the token is reported as unquoted, but ends with a (unescaped) quote, and we can // modify the command line, then delete the trailing quote so that we can insert within @@ -1435,7 +1435,7 @@ void reader_data_t::flash() { pollint.tv_sec = 0; pollint.tv_nsec = 100 * 1000000; - nanosleep(&pollint, NULL); + nanosleep(&pollint, nullptr); super_highlight_me_plenty(); repaint(); @@ -1660,7 +1660,7 @@ static bool check_for_orphaned_process(unsigned long loop_count, pid_t shell_pgi char buf[L_ctermid]; char *tty = ctermid_r(buf); #else - char *tty = ctermid(NULL); + char *tty = ctermid(nullptr); #endif if (!tty) { wperror(L"ctermid"); @@ -1834,7 +1834,7 @@ void reader_data_t::replace_current_token(const wcstring &new_token) { // Find current token. editable_line_t *el = active_edit_line(); const wchar_t *buff = el->text.c_str(); - parse_util_token_extent(buff, el->position, &begin, &end, 0, 0); + parse_util_token_extent(buff, el->position, &begin, &end, nullptr, nullptr); if (!begin || !end) return; @@ -1950,12 +1950,12 @@ void reader_run_command(parser_t &parser, const wcstring &cmd) { reader_write_title(cmd, parser); term_donate(outp); - gettimeofday(&time_before, NULL); + gettimeofday(&time_before, nullptr); parser.eval(cmd, io_chain_t(), TOP); job_reap(parser, true); - gettimeofday(&time_after, NULL); + gettimeofday(&time_after, nullptr); // update the execution duration iff a command is requested for execution // issue - #4926 @@ -2041,7 +2041,7 @@ static std::function get_highlight_performer( } s_thread_generation = generation_count; std::vector colors(text.size(), highlight_spec_t{}); - highlight_func(text, colors, match_highlight_pos, NULL /* error */, *vars); + highlight_func(text, colors, match_highlight_pos, nullptr /* error */, *vars); return {std::move(colors), text}; }; } @@ -2056,7 +2056,7 @@ static std::function get_highlight_performer( /// an asynchronous highlight in the background, which may perform disk I/O. void reader_data_t::super_highlight_me_plenty(int match_highlight_pos_adjust, bool no_io) { const editable_line_t *el = &command_line; - assert(el != NULL); + assert(el != nullptr); long match_highlight_pos = static_cast(el->position) + match_highlight_pos_adjust; assert(match_highlight_pos >= 0); @@ -2318,7 +2318,7 @@ static int can_read(int fd) { FD_ZERO(&fds); FD_SET(fd, &fds); - return select(fd + 1, &fds, 0, 0, &can_read_timeout) == 1; + return select(fd + 1, &fds, nullptr, nullptr, &can_read_timeout) == 1; } /// Test if the specified character in the specified string is backslashed. pos may be at the end of @@ -2551,7 +2551,7 @@ void reader_data_t::handle_readline_command(readline_cmd_t c, readline_loop_stat // pass cmdsub_begin here, not buff. const wchar_t *token_begin, *token_end; parse_util_token_extent(cmdsub_begin, el->position - (cmdsub_begin - buff), - &token_begin, &token_end, 0, 0); + &token_begin, &token_end, nullptr, nullptr); // Hack: the token may extend past the end of the command substitution, e.g. in // (echo foo) the last token is 'foo)'. Don't let that happen. @@ -2771,7 +2771,7 @@ void reader_data_t::handle_readline_command(readline_cmd_t c, readline_loop_stat // Finished command, execute it. Don't add items that start with a leading // space. const editable_line_t *el = &command_line; - if (history != NULL && !el->empty() && el->text.at(0) != L' ') { + if (history != nullptr && !el->empty() && el->text.at(0) != L' ') { history->add_pending_with_file_detection(el->text, vars.get_pwd_slash()); } rls.finished = true; @@ -2810,7 +2810,7 @@ void reader_data_t::handle_readline_command(readline_cmd_t c, readline_loop_stat // Searching by token. const wchar_t *begin, *end; const wchar_t *buff = el->text.c_str(); - parse_util_token_extent(buff, el->position, &begin, &end, 0, 0); + parse_util_token_extent(buff, el->position, &begin, &end, nullptr, nullptr); if (begin) { wcstring token(begin, end); history_search.reset_to_mode(token, history, @@ -3452,13 +3452,13 @@ void reader_react_to_color_change() { const wchar_t *reader_get_buffer() { ASSERT_IS_MAIN_THREAD(); reader_data_t *data = current_data_or_null(); - return data ? data->command_line.text.c_str() : NULL; + return data ? data->command_line.text.c_str() : nullptr; } history_t *reader_get_history() { ASSERT_IS_MAIN_THREAD(); reader_data_t *data = current_data_or_null(); - return data ? data->history : NULL; + return data ? data->history : nullptr; } void reader_sanity_check() { @@ -3486,7 +3486,7 @@ size_t reader_get_cursor_pos() { bool reader_get_selection(size_t *start, size_t *len) { bool result = false; reader_data_t *data = current_data_or_null(); - if (data != NULL && data->sel_active) { + if (data != nullptr && data->sel_active) { *start = data->sel_start_pos; *len = std::min(data->sel_stop_pos - data->sel_start_pos, data->command_line.size()); result = true; @@ -3509,7 +3509,7 @@ static int read_ni(parser_t &parser, int fd, const io_chain_t &io) { } in_stream = fdopen(des, "r"); - if (in_stream != 0) { + if (in_stream != nullptr) { while (!feof(in_stream)) { char buff[4096]; size_t c = fread(buff, 1, 4096, in_stream); diff --git a/src/sanity.cpp b/src/sanity.cpp index 677214384..cbe4b0e82 100644 --- a/src/sanity.cpp +++ b/src/sanity.cpp @@ -29,7 +29,7 @@ void validate_pointer(const void *ptr, const wchar_t *err, int null_ok) { sanity_lose(); } - if ((!null_ok) && (ptr == 0)) { + if ((!null_ok) && (ptr == nullptr)) { FLOGF(error, _(L"The pointer '%ls' is null"), err); sanity_lose(); } diff --git a/src/screen.cpp b/src/screen.cpp index ac4b8d62d..d441e88d1 100644 --- a/src/screen.cpp +++ b/src/screen.cpp @@ -104,7 +104,7 @@ static bool is_screen_name_escape_seq(const wchar_t *code, size_t *resulting_len } const wchar_t *const screen_name_end_sentinel = L"\x1B\\"; const wchar_t *screen_name_end = std::wcsstr(&code[2], screen_name_end_sentinel); - if (screen_name_end == NULL) { + if (screen_name_end == nullptr) { // Consider just k to be the code. *resulting_length = 2; } else { @@ -246,7 +246,7 @@ static bool is_visual_escape_seq(const wchar_t *code, size_t *resulting_length) /// that begin with \x1B. If it doesn't we return zero. We also return zero if we don't recognize /// the escape sequence based on querying terminfo and other heuristics. size_t escape_code_length(const wchar_t *code) { - assert(code != NULL); + assert(code != nullptr); if (*code != L'\x1B') return 0; size_t esc_seq_len = cached_layouts.find_escape_code(code); @@ -498,7 +498,7 @@ static void s_move(screen_t *s, int new_x, int new_y) { x_steps = 0; } - const char *multi_str = NULL; + const char *multi_str = nullptr; if (x_steps < 0) { str = cursor_left; multi_str = parm_left_cursor; @@ -509,7 +509,7 @@ static void s_move(screen_t *s, int new_x, int new_y) { // Use the bulk ('multi') output for cursor movement if it is supported and it would be shorter // Note that this is required to avoid some visual glitches in iTerm (issue #1448). - bool use_multi = multi_str != NULL && multi_str[0] != '\0' && + bool use_multi = multi_str != nullptr && multi_str[0] != '\0' && abs(x_steps) * std::strlen(str) > std::strlen(multi_str); if (use_multi && cur_term) { char *multi_param = tparm(const_cast(multi_str), abs(x_steps)); @@ -663,7 +663,7 @@ static void s_update(screen_t *scr, const wcstring &left_prompt, const wcstring // If this is the last line, maybe we should clear the screen. const bool should_clear_screen_this_line = - need_clear_screen && i + 1 == scr->desired.line_count() && clr_eos != NULL; + need_clear_screen && i + 1 == scr->desired.line_count() && clr_eos != nullptr; // Note that skip_remaining is a width, not a character count. size_t skip_remaining = start_pos; diff --git a/src/signal.cpp b/src/signal.cpp index a9837d863..c17587cea 100644 --- a/src/signal.cpp +++ b/src/signal.cpp @@ -268,10 +268,10 @@ void signal_reset_handlers() { for (const auto &data : signal_table) { if (data.signal == SIGHUP) { struct sigaction oact; - sigaction(SIGHUP, NULL, &oact); + sigaction(SIGHUP, nullptr, &oact); if (oact.sa_handler == SIG_IGN) continue; } - sigaction(data.signal, &act, NULL); + sigaction(data.signal, &act, nullptr); } } @@ -284,35 +284,35 @@ static void set_interactive_handlers() { // Interactive mode. Ignore interactive signals. We are a shell, we know what is best for // the user. act.sa_handler = SIG_IGN; - sigaction(SIGTSTP, &act, NULL); - sigaction(SIGTTOU, &act, NULL); + sigaction(SIGTSTP, &act, nullptr); + sigaction(SIGTTOU, &act, nullptr); // We don't ignore SIGTTIN because we might send it to ourself. act.sa_sigaction = &fish_signal_handler; act.sa_flags = SA_SIGINFO; - sigaction(SIGTTIN, &act, NULL); + sigaction(SIGTTIN, &act, nullptr); // SIGTERM restores the terminal controlling process before dying. act.sa_sigaction = &fish_signal_handler; act.sa_flags = SA_SIGINFO; - sigaction(SIGTERM, &act, NULL); + sigaction(SIGTERM, &act, nullptr); - sigaction(SIGHUP, NULL, &oact); + sigaction(SIGHUP, nullptr, &oact); if (oact.sa_handler == SIG_DFL) { act.sa_sigaction = &fish_signal_handler; act.sa_flags = SA_SIGINFO; - sigaction(SIGHUP, &act, NULL); + sigaction(SIGHUP, &act, nullptr); } // SIGALARM as part of our signal torture test act.sa_sigaction = &fish_signal_handler; act.sa_flags = SA_SIGINFO; - sigaction(SIGALRM, &act, NULL); + sigaction(SIGALRM, &act, nullptr); #ifdef SIGWINCH act.sa_sigaction = &fish_signal_handler; act.sa_flags = SA_SIGINFO; - sigaction(SIGWINCH, &act, NULL); + sigaction(SIGWINCH, &act, nullptr); #endif } @@ -326,22 +326,22 @@ void signal_set_handlers(bool interactive) { // this signal interrupting other syscalls or terminating us. act.sa_sigaction = nullptr; act.sa_handler = SIG_IGN; - sigaction(SIGPIPE, &act, 0); + sigaction(SIGPIPE, &act, nullptr); // Ignore SIGQUIT. act.sa_handler = SIG_IGN; - sigaction(SIGQUIT, &act, 0); + sigaction(SIGQUIT, &act, nullptr); // Apply our SIGINT handler. act.sa_sigaction = &fish_signal_handler; act.sa_flags = SA_SIGINFO; - sigaction(SIGINT, &act, NULL); + sigaction(SIGINT, &act, nullptr); // Whether or not we're interactive we want SIGCHLD to not interrupt restartable syscalls. act.sa_flags = SA_SIGINFO; act.sa_sigaction = &fish_signal_handler; act.sa_flags = SA_SIGINFO | SA_RESTART; - if (sigaction(SIGCHLD, &act, 0)) { + if (sigaction(SIGCHLD, &act, nullptr)) { wperror(L"sigaction"); FATAL_EXIT(); } @@ -378,7 +378,7 @@ void get_signals_with_handlers(sigset_t *set) { sigemptyset(set); for (const auto &data : signal_table) { struct sigaction act = {}; - sigaction(data.signal, NULL, &act); + sigaction(data.signal, nullptr, &act); // If SIGHUP is being ignored (e.g., because were were run via `nohup`) don't reset it. // We don't special case other signals because if they're being ignored that shouldn't // affect processes we spawn. They should get the default behavior for those signals. @@ -391,7 +391,7 @@ void get_signals_with_handlers(sigset_t *set) { void signal_unblock_all() { sigset_t iset; sigemptyset(&iset); - sigprocmask(SIG_SETMASK, &iset, NULL); + sigprocmask(SIG_SETMASK, &iset, nullptr); } sigint_checker_t::sigint_checker_t() { diff --git a/src/tinyexpr.cpp b/src/tinyexpr.cpp index c024b6401..c84c02436 100644 --- a/src/tinyexpr.cpp +++ b/src/tinyexpr.cpp @@ -205,7 +205,7 @@ static const te_builtin *find_builtin(const char *name, int len) { }); // We need to compare again because we might have gotten the first "larger" element. if (found != end && std::strncmp(found->name, name, len) == 0) return found; - return NULL; + return nullptr; } static constexpr double add(double a, double b) { return a + b; } @@ -336,13 +336,13 @@ static te_expr *base(state *s) { switch (s->type) { case TOK_NUMBER: - ret = new_expr(TE_CONSTANT, 0); + ret = new_expr(TE_CONSTANT, nullptr); ret->value = s->value; next_token(s); break; case TE_FUNCTION0: - ret = new_expr(s->type, 0); + ret = new_expr(s->type, nullptr); ret->function = s->function; next_token(s); if (s->type == TOK_OPEN) { @@ -361,7 +361,7 @@ static te_expr *base(state *s) { case TE_FUNCTION3: arity = get_arity(s->type); - ret = new_expr(s->type, 0); + ret = new_expr(s->type, nullptr); ret->function = s->function; next_token(s); @@ -404,13 +404,13 @@ static te_expr *base(state *s) { // This means we have too few things. // Instead of introducing another error, just call it // "too few args". - ret = new_expr(0, 0); + ret = new_expr(0, nullptr); s->type = TOK_ERROR; s->error = TE_ERROR_TOO_FEW_ARGS; ret->value = NAN; break; default: - ret = new_expr(0, 0); + ret = new_expr(0, nullptr); s->type = TOK_ERROR; s->error = TE_ERROR_UNEXPECTED_TOKEN; ret->value = NAN; @@ -444,7 +444,7 @@ static te_expr *factor(state *s) { /* = {"^" } */ te_expr *ret = power(s); - te_expr *insertion = 0; + te_expr *insertion = nullptr; while (s->type == TOK_INFIX && (s->function == reinterpret_cast(static_cast(pow)))) { @@ -566,7 +566,7 @@ te_expr *te_compile(const char *expression, te_error_t *error) { error->type = TE_ERROR_TOO_MANY_ARGS; } } - return 0; + return nullptr; } else { optimize(root); if (error) error->position = 0; diff --git a/src/tnode.cpp b/src/tnode.cpp index b29e82d28..e84e88c5c 100644 --- a/src/tnode.cpp +++ b/src/tnode.cpp @@ -9,12 +9,12 @@ const parse_node_t *parse_node_tree_t::next_node_in_node_list( assert(list_type != entry_type); const parse_node_t *list_cursor = &node_list; - const parse_node_t *list_entry = NULL; + const parse_node_t *list_entry = nullptr; // Loop while we don't have an item but do have a list. Note that some nodes may contain // nothing; e.g. job_list contains blank lines as a production. - while (list_entry == NULL && list_cursor != NULL) { - const parse_node_t *next_cursor = NULL; + while (list_entry == nullptr && list_cursor != nullptr) { + const parse_node_t *next_cursor = nullptr; // Walk through the children. for (node_offset_t i = 0; i < list_cursor->child_count; i++) { @@ -32,9 +32,9 @@ const parse_node_t *parse_node_tree_t::next_node_in_node_list( } // Return what we got. - assert(list_cursor == NULL || list_cursor->type == list_type); - assert(list_entry == NULL || list_entry->type == entry_type); - if (out_list_tail != NULL) *out_list_tail = list_cursor; + assert(list_cursor == nullptr || list_cursor->type == list_type); + assert(list_entry == nullptr || list_entry->type == entry_type); + if (out_list_tail != nullptr) *out_list_tail = list_cursor; return list_entry; } @@ -67,7 +67,7 @@ maybe_t redirection_for_node(tnode_t redi assert(result.has_value() && "Failed to parse valid redirection"); assert(!result->is_pipe && "Should not be a pipe"); } - if (out_target != NULL) { + if (out_target != nullptr) { tnode_t target = redirection.child<1>(); // like 1 or file path *out_target = target.has_source() ? target.get_source(src) : wcstring(); } diff --git a/src/utf8.cpp b/src/utf8.cpp index 21484cf33..843492e60 100644 --- a/src/utf8.cpp +++ b/src/utf8.cpp @@ -65,7 +65,7 @@ bool wchar_to_utf8_string(const std::wstring &str, std::string *result) { bool success = false; const wchar_t *input = str.c_str(); - size_t outlen = wchar_to_utf8(input, inlen, NULL, 0, 0); + size_t outlen = wchar_to_utf8(input, inlen, nullptr, 0, 0); if (outlen > 0) { char *tmp = new char[outlen]; size_t outlen2 = wchar_to_utf8(input, inlen, tmp, outlen, 0); @@ -79,15 +79,15 @@ bool wchar_to_utf8_string(const std::wstring &str, std::string *result) { } size_t utf8_to_wchar(const char *in, size_t insize, std::wstring *out, int flags) { - if (in == NULL || insize == 0) { + if (in == nullptr || insize == 0) { return 0; } size_t result; if (sizeof(wchar_t) == sizeof(utf8_wchar_t)) { //!OCLINT(constant if expression) result = utf8_to_wchar_internal(in, insize, reinterpret_cast(out), flags); - } else if (out == NULL) { - result = utf8_to_wchar_internal(in, insize, NULL, flags); + } else if (out == nullptr) { + result = utf8_to_wchar_internal(in, insize, nullptr, flags); } else { // Allocate a temporary buffer to hold the output, invoke the conversion with the temporary, // and then copy it back. @@ -99,7 +99,7 @@ size_t utf8_to_wchar(const char *in, size_t insize, std::wstring *out, int flags } size_t wchar_to_utf8(const wchar_t *in, size_t insize, char *out, size_t outsize, int flags) { - if (in == NULL || insize == 0 || (outsize == 0 && out != NULL)) { + if (in == nullptr || insize == 0 || (outsize == 0 && out != nullptr)) { return 0; } @@ -171,9 +171,9 @@ static size_t utf8_to_wchar_internal(const char *in, size_t insize, utf8_wstring utf8_wchar_t high; size_t n, total, i, n_bits; - if (in == NULL || insize == 0) return 0; + if (in == nullptr || insize == 0) return 0; - if (out_string != NULL) out_string->clear(); + if (out_string != nullptr) out_string->clear(); total = 0; p = (unsigned char *)in; @@ -220,7 +220,7 @@ static size_t utf8_to_wchar_internal(const char *in, size_t insize, utf8_wstring } total++; - if (out_string == NULL) continue; + if (out_string == nullptr) continue; uint32_t out_val = 0; n_bits = 0; @@ -272,7 +272,7 @@ static size_t wchar_to_utf8_internal(const utf8_wchar_t *in, size_t insize, char unsigned char *p, *lim; size_t total, n; - if (in == NULL || insize == 0 || (outsize == 0 && out != NULL)) return 0; + if (in == nullptr || insize == 0 || (outsize == 0 && out != nullptr)) return 0; w = in; wlim = w + insize; @@ -306,7 +306,7 @@ static size_t wchar_to_utf8_internal(const utf8_wchar_t *in, size_t insize, char total += n; - if (out == NULL) continue; + if (out == nullptr) continue; if (size_t(lim - p) <= n - 1) return 0; // no space left // Extract the wchar_t as big-endian. If wchar_t is UCS-16, the first two bytes will be 0. diff --git a/src/util.cpp b/src/util.cpp index 74c03d5c8..dcbbc2eac 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -103,6 +103,6 @@ int wcsfilecmp(const wchar_t *a, const wchar_t *b) { /// Return microseconds since the epoch. long long get_time() { struct timeval time_struct; - gettimeofday(&time_struct, 0); + gettimeofday(&time_struct, nullptr); return 1000000ll * time_struct.tv_sec + time_struct.tv_usec; } diff --git a/src/wgetopt.cpp b/src/wgetopt.cpp index 031b691db..f64515763 100644 --- a/src/wgetopt.cpp +++ b/src/wgetopt.cpp @@ -115,7 +115,7 @@ void wgetopter_t::_wgetopt_initialize(const wchar_t *optstring) { // Start processing options with ARGV-element 1 (since ARGV-element 0 is the program name); the // sequence of previously skipped non-option ARGV-elements is empty. first_nonopt = last_nonopt = woptind = 1; - nextchar = NULL; + nextchar = nullptr; // Determine how to handle the ordering of options and nonoptions. if (optstring[0] == '-') { @@ -191,7 +191,7 @@ int wgetopter_t::_advance_to_next_argv( //!OCLINT(high cyclomatic complexity) } // We have found another option-ARGV-element. Skip the initial punctuation. - nextchar = (argv[woptind] + 1 + (longopts != NULL && argv[woptind][1] == '-')); + nextchar = (argv[woptind] + 1 + (longopts != nullptr && argv[woptind][1] == '-')); return 0; } @@ -204,7 +204,7 @@ int wgetopter_t::_handle_short_opt(int argc, wchar_t **argv) { // Increment `woptind' when we start to process its last character. if (*nextchar == '\0') ++woptind; - if (temp == NULL || c == ':') { + if (temp == nullptr || c == ':') { if (wopterr) { std::fwprintf(stderr, _(L"%ls: Invalid option -- %lc\n"), argv[0], static_cast(c)); @@ -225,9 +225,9 @@ int wgetopter_t::_handle_short_opt(int argc, wchar_t **argv) { woptarg = nextchar; woptind++; } else { - woptarg = NULL; + woptarg = nullptr; } - nextchar = NULL; + nextchar = nullptr; } else { // This is an option that requires an argument. if (*nextchar != '\0') { @@ -248,7 +248,7 @@ int wgetopter_t::_handle_short_opt(int argc, wchar_t **argv) { // ARGV-elt as argument. woptarg = argv[woptind++]; } - nextchar = NULL; + nextchar = nullptr; } return c; @@ -290,7 +290,7 @@ void wgetopter_t::_update_long_opt(int argc, wchar_t **argv, const struct woptio } nextchar += std::wcslen(nextchar); - if (longind != NULL) *longind = option_index; + if (longind != nullptr) *longind = option_index; if (pfound->flag) { *(pfound->flag) = pfound->val; *retval = 0; @@ -303,7 +303,7 @@ void wgetopter_t::_update_long_opt(int argc, wchar_t **argv, const struct woptio const struct woption *wgetopter_t::_find_matching_long_opt(const struct woption *longopts, wchar_t *nameend, int *exact, int *ambig, int *indfound) { - const struct woption *pfound = NULL; + const struct woption *pfound = nullptr; int option_index = 0; // Test all long options for either exact match or abbreviated matches. @@ -316,7 +316,7 @@ const struct woption *wgetopter_t::_find_matching_long_opt(const struct woption *indfound = option_index; *exact = 1; break; - } else if (pfound == NULL) { + } else if (pfound == nullptr) { // First nonexact match found. pfound = p; *indfound = option_index; @@ -361,7 +361,7 @@ bool wgetopter_t::_handle_long_opt(int argc, wchar_t **argv, const struct woptio // Can't find it as a long option. If this is not getopt_long_only, or the option starts // with '--' or is not a valid short option, then it's an error. Otherwise interpret it as a // short option. - if (!long_only || argv[woptind][1] == '-' || std::wcschr(shortopts, *nextchar) == NULL) { + if (!long_only || argv[woptind][1] == '-' || std::wcschr(shortopts, *nextchar) == nullptr) { if (wopterr) { if (argv[woptind][1] == '-') // --option std::fwprintf(stderr, _(L"%ls: Unrecognized option '--%ls'\n"), argv[0], nextchar); @@ -422,9 +422,9 @@ bool wgetopter_t::_handle_long_opt(int argc, wchar_t **argv, const struct woptio int wgetopter_t::_wgetopt_internal(int argc, wchar_t **argv, const wchar_t *optstring, const struct woption *longopts, int *longind, int long_only) { if (!initialized) _wgetopt_initialize(optstring); - woptarg = NULL; + woptarg = nullptr; - if (nextchar == NULL || *nextchar == '\0') { + if (nextchar == nullptr || *nextchar == '\0') { int retval = _advance_to_next_argv(argc, argv, longopts); if (retval != 0) return retval; } @@ -442,7 +442,7 @@ int wgetopter_t::_wgetopt_internal(int argc, wchar_t **argv, const wchar_t *opts // "u". // // This distinction seems to be the most useful approach. - if (longopts != NULL && + if (longopts != nullptr && (argv[woptind][1] == '-' || (long_only && (argv[woptind][2] || !std::wcschr(shortopts, argv[woptind][1]))))) { int retval; diff --git a/src/wildcard.cpp b/src/wildcard.cpp index c38ea25a0..da31fcd0c 100644 --- a/src/wildcard.cpp +++ b/src/wildcard.cpp @@ -62,7 +62,7 @@ static size_t wildcard_find(const wchar_t *wc) { /// Implementation of wildcard_has. Needs to take the length to handle embedded nulls (issue #1631). static bool wildcard_has_impl(const wchar_t *str, size_t len, bool internal) { - assert(str != NULL); + assert(str != nullptr); bool qmark_is_wild = !feature_test(features_t::qmark_noglob); const wchar_t *end = str + len; if (internal) { @@ -82,7 +82,7 @@ static bool wildcard_has_impl(const wchar_t *str, size_t len, bool internal) { } bool wildcard_has(const wchar_t *str, bool internal) { - assert(str != NULL); + assert(str != nullptr); return wildcard_has_impl(str, std::wcslen(str), internal); } @@ -183,7 +183,7 @@ struct wc_complete_pack_t { // Weirdly specific and non-reusable helper function that makes its one call site much clearer. static bool has_prefix_match(const std::vector *comps, size_t first) { - if (comps != NULL) { + if (comps != nullptr) { const size_t after_count = comps->size(); for (size_t j = first; j < after_count; j++) { if (comps->at(j).match.type <= fuzzy_match_prefix) { @@ -202,8 +202,8 @@ static bool has_prefix_match(const std::vector *comps, size_t firs static bool wildcard_complete_internal(const wchar_t *str, const wchar_t *wc, const wc_complete_pack_t ¶ms, complete_flags_t flags, std::vector *out, bool is_first_call = false) { - assert(str != NULL); - assert(wc != NULL); + assert(str != nullptr); + assert(wc != nullptr); // Maybe early out for hidden files. We require that the wildcard match these exactly (i.e. a // dot); ANY_STRING not allowed. @@ -226,7 +226,7 @@ static bool wildcard_complete_internal(const wchar_t *str, const wchar_t *wc, match_acceptable = match_type_shares_prefix(match.type); } - if (!match_acceptable || out == NULL) { + if (!match_acceptable || out == nullptr) { return match_acceptable; } @@ -291,7 +291,7 @@ static bool wildcard_complete_internal(const wchar_t *str, const wchar_t *wc, // If out is NULL, we don't care about the actual matches. If out is not // NULL but we have a prefix match, stop there. - if (out == NULL || has_prefix_match(out, before_count)) { + if (out == nullptr || has_prefix_match(out, before_count)) { break; } } @@ -316,7 +316,7 @@ bool wildcard_complete(const wcstring &str, const wchar_t *wc, std::vector *out, expand_flags_t expand_flags, complete_flags_t flags) { // Note out may be NULL. - assert(wc != NULL); + assert(wc != nullptr); wc_complete_pack_t params(str, desc_func, expand_flags); return wildcard_complete_internal(str.c_str(), wc, params, flags, out, true /* first call */); } @@ -390,7 +390,7 @@ static bool wildcard_test_flags_then_complete(const wcstring &filepath, const wc const wchar_t *wc, expand_flags_t expand_flags, std::vector *out) { // Check if it will match before stat(). - if (!wildcard_complete(filename, wc, {}, NULL, expand_flags, 0)) { + if (!wildcard_complete(filename, wc, {}, nullptr, expand_flags, 0)) { return false; } @@ -634,7 +634,7 @@ class wildcard_expander_t { did_interrupt(false), did_add(false), has_fuzzy_ancestor(false) { - assert(resolved_completions != NULL); + assert(resolved_completions != nullptr); // Insert initial completions into our set to avoid duplicates. for (std::vector::const_iterator iter = resolved_completions->begin(); @@ -813,7 +813,7 @@ void wildcard_expander_t::expand_last_segment(const wcstring &base_dir, DIR *bas // expansions void wildcard_expander_t::expand(const wcstring &base_dir, const wchar_t *wc, const wcstring &effective_prefix) { - assert(wc != NULL); + assert(wc != nullptr); if (interrupted()) { return; @@ -822,12 +822,12 @@ void wildcard_expander_t::expand(const wcstring &base_dir, const wchar_t *wc, // Get the current segment and compute interesting properties about it. const size_t wc_len = std::wcslen(wc); const wchar_t *const next_slash = std::wcschr(wc, L'/'); - const bool is_last_segment = (next_slash == NULL); + const bool is_last_segment = (next_slash == nullptr); const size_t wc_segment_len = next_slash ? next_slash - wc : wc_len; const wcstring wc_segment = wcstring(wc, wc_segment_len); const bool segment_has_wildcards = wildcard_has(wc_segment, true /* internal, i.e. look for ANY_CHAR instead of ? */); - const wchar_t *const wc_remainder = next_slash ? next_slash + 1 : NULL; + const wchar_t *const wc_remainder = next_slash ? next_slash + 1 : nullptr; if (wc_segment.empty()) { // Handle empty segment. @@ -841,7 +841,7 @@ void wildcard_expander_t::expand(const wcstring &base_dir, const wchar_t *wc, } else if (!segment_has_wildcards && !is_last_segment) { // Literal intermediate match. Note that we may not be able to actually read the directory // (issue #2099). - assert(next_slash != NULL); + assert(next_slash != nullptr); // Absolute path of the intermediate directory const wcstring intermediate_dirpath = base_dir + wc_segment + L'/'; @@ -859,7 +859,7 @@ void wildcard_expander_t::expand(const wcstring &base_dir, const wchar_t *wc, waccess(intermediate_dirpath, F_OK) != 0) { assert(this->flags & expand_flag::for_completions); DIR *base_dir_fd = open_dir(base_dir); - if (base_dir_fd != NULL) { + if (base_dir_fd != nullptr) { this->expand_literal_intermediate_segment_with_fuzz( base_dir, base_dir_fd, wc_segment, wc_remainder, effective_prefix); closedir(base_dir_fd); @@ -874,7 +874,7 @@ void wildcard_expander_t::expand(const wcstring &base_dir, const wchar_t *wc, this->expand_last_segment(base_dir, dir, wc_segment, effective_prefix); } else { // Not the last segment, nonempty wildcard. - assert(next_slash != NULL); + assert(next_slash != nullptr); this->expand_intermediate_segment(base_dir, dir, wc_segment, wc_remainder, effective_prefix + wc_segment + L'/'); } @@ -901,7 +901,7 @@ void wildcard_expander_t::expand(const wcstring &base_dir, const wchar_t *wc, int wildcard_expand_string(const wcstring &wc, const wcstring &working_directory, expand_flags_t flags, std::vector *output) { - assert(output != NULL); + assert(output != nullptr); // Fuzzy matching only if we're doing completions. assert(flags.get(expand_flag::for_completions) || !flags.get(expand_flag::fuzzy_match)); diff --git a/src/wutil.cpp b/src/wutil.cpp index 52a0f6ffb..330ccb70b 100644 --- a/src/wutil.cpp +++ b/src/wutil.cpp @@ -102,7 +102,7 @@ bool wreaddir(DIR *dir, wcstring &out_name) { } bool wreaddir_for_dirs(DIR *dir, wcstring *out_name) { - struct dirent *result = NULL; + struct dirent *result = nullptr; while (!result) { result = readdir(dir); if (!result) break; @@ -162,7 +162,7 @@ FILE *wfopen(const wcstring &path, const char *mode) { } default: { errno = EINVAL; - return NULL; + return nullptr; } } // Skip binary. @@ -172,9 +172,9 @@ FILE *wfopen(const wcstring &path, const char *mode) { if (mode[idx] == '+') permissions = O_RDWR; int fd = wopen_cloexec(path, permissions | options, 0666); - if (fd < 0) return NULL; + if (fd < 0) return nullptr; FILE *result = fdopen(fd, mode); - if (result == NULL) close(fd); + if (result == nullptr) close(fd); return result; } @@ -337,7 +337,7 @@ const char *safe_strerror(int err) { return std::strerror(err); #elif defined(HAVE__SYS__ERRS) || defined(HAVE_SYS_ERRLIST) #ifdef HAVE_SYS_ERRLIST - if (err >= 0 && err < sys_nerr && sys_errlist[err] != NULL) { + if (err >= 0 && err < sys_nerr && sys_errlist[err] != nullptr) { return sys_errlist[err]; } #elif defined(HAVE__SYS__ERRS) @@ -618,7 +618,7 @@ int fish_wcswidth(const wchar_t *str) { return fish_wcswidth(str, std::wcslen(st int fish_wcswidth(const wcstring &str) { return fish_wcswidth(str.c_str(), str.size()); } locale_t fish_c_locale() { - static const locale_t loc = newlocale(LC_ALL_MASK, "C", NULL); + static const locale_t loc = newlocale(LC_ALL_MASK, "C", nullptr); return loc; } diff --git a/src/wutil.h b/src/wutil.h index ca261f63a..0363e4f13 100644 --- a/src/wutil.h +++ b/src/wutil.h @@ -142,10 +142,11 @@ int fish_wcswidth(const wcstring &str); // returns an immortal locale_t corresponding to the C locale. locale_t fish_c_locale(); -int fish_wcstoi(const wchar_t *str, const wchar_t **endptr = NULL, int base = 10); -long fish_wcstol(const wchar_t *str, const wchar_t **endptr = NULL, int base = 10); -long long fish_wcstoll(const wchar_t *str, const wchar_t **endptr = NULL, int base = 10); -unsigned long long fish_wcstoull(const wchar_t *str, const wchar_t **endptr = NULL, int base = 10); +int fish_wcstoi(const wchar_t *str, const wchar_t **endptr = nullptr, int base = 10); +long fish_wcstol(const wchar_t *str, const wchar_t **endptr = nullptr, int base = 10); +long long fish_wcstoll(const wchar_t *str, const wchar_t **endptr = nullptr, int base = 10); +unsigned long long fish_wcstoull(const wchar_t *str, const wchar_t **endptr = nullptr, + int base = 10); double fish_wcstod(const wchar_t *str, wchar_t **endptr); /// Class for representing a file's inode. We use this to detect and avoid symlink loops, among