diff --git a/.cppcheck.suppressions b/.cppcheck.suppressions index abe53fc0f..a2991396b 100644 --- a/.cppcheck.suppressions +++ b/.cppcheck.suppressions @@ -9,6 +9,5 @@ varFuncNullUB // warnings are false positives. unmatchedSuppression -memleak:src/env_universal_common.cpp flockSemanticsWarning:src/env_universal_common.cpp flockSemanticsWarning:src/history.cpp diff --git a/build_tools/iwyu.osx.imp b/build_tools/iwyu.osx.imp index ee9353021..e00305fed 100644 --- a/build_tools/iwyu.osx.imp +++ b/build_tools/iwyu.osx.imp @@ -84,6 +84,7 @@ { symbol: ["uid_t", "private", "", "public"] }, { symbol: ["gid_t", "private", "", "public"] }, { symbol: ["timeval", "private", "", "public"] }, + { symbol: ["__uint32_t", "private", "", "public"] }, { symbol: ["uint32_t", "private", "", "public"] }, { symbol: ["uint32_t", "private", "", "public"] }, { symbol: ["intptr_t", "private", "", "public"] }, diff --git a/src/autoload.cpp b/src/autoload.cpp index e63997863..960b586e7 100644 --- a/src/autoload.cpp +++ b/src/autoload.cpp @@ -1,17 +1,16 @@ // The classes responsible for autoloading functions and completions. #include "config.h" // IWYU pragma: keep +#include #include #include -#include #include #include #include -#include -#include #include #include #include +#include #include #include diff --git a/src/autoload.h b/src/autoload.h index 7a661b4b4..6a395cf08 100644 --- a/src/autoload.h +++ b/src/autoload.h @@ -3,7 +3,6 @@ #define FISH_AUTOLOAD_H #include -#include #include #include diff --git a/src/builtin_commandline.cpp b/src/builtin_commandline.cpp index d47d6f534..2ba5b2356 100644 --- a/src/builtin_commandline.cpp +++ b/src/builtin_commandline.cpp @@ -3,10 +3,8 @@ #include #include -#include #include #include -#include #include "builtin.h" #include "common.h" diff --git a/src/builtin_string.cpp b/src/builtin_string.cpp index fc27df8fa..3547e88c8 100644 --- a/src/builtin_string.cpp +++ b/src/builtin_string.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -585,8 +586,7 @@ static int string_match(parser_t &parser, io_streams_t &streams, int argc, wchar } } - int rc = matcher->match_count() > 0 ? BUILTIN_STRING_OK : BUILTIN_STRING_NONE; - return rc; + return matcher->match_count() > 0 ? BUILTIN_STRING_OK : BUILTIN_STRING_NONE; } struct replace_options_t { @@ -819,8 +819,7 @@ static int string_replace(parser_t &parser, io_streams_t &streams, int argc, wch } } - int rc = replacer->replace_count() > 0 ? BUILTIN_STRING_OK : BUILTIN_STRING_NONE; - return rc; + return replacer->replace_count() > 0 ? BUILTIN_STRING_OK : BUILTIN_STRING_NONE; } /// Given iterators into a string (forward or reverse), splits the haystack iterators diff --git a/src/builtin_test.cpp b/src/builtin_test.cpp index 9e5352dcd..2842806dd 100644 --- a/src/builtin_test.cpp +++ b/src/builtin_test.cpp @@ -6,13 +6,13 @@ #include #include #include -#include #include #include #include #include #include #include +#include #include "builtin.h" #include "common.h" @@ -234,7 +234,7 @@ class combining_expression : public expression { combining_expression(token_t tok, range_t where, std::vector> exprs, std::vector combs) - : expression(tok, where), subjects(move(exprs)), combiners(move(combs)) { + : expression(tok, where), subjects(std::move(exprs)), combiners(std::move(combs)) { // We should have one more subject than combiner. assert(subjects.size() == combiners.size() + 1); } diff --git a/src/common.cpp b/src/common.cpp index b03aad111..174cbd575 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -30,6 +31,7 @@ #endif #include #include // IWYU pragma: keep +#include #include "common.h" #include "env.h" @@ -1783,12 +1785,11 @@ void save_term_foreground_process_group(void) { } void restore_term_foreground_process_group(void) { - if (initial_fg_process_group != -1) { - // This is called during shutdown and from a signal handler. We don't bother to complain on - // failure. - if (tcsetpgrp(STDIN_FILENO, initial_fg_process_group) == -1 && errno == ENOTTY) { - redirect_tty_output(); - } + if (initial_fg_process_group == -1) return; + // This is called during shutdown and from a signal handler. We don't bother to complain on + // failure because doing so is unlikely to be noticed. + if (tcsetpgrp(STDIN_FILENO, initial_fg_process_group) == -1 && errno == ENOTTY) { + redirect_tty_output(); } } diff --git a/src/common.h b/src/common.h index 964b350c8..91d4396b4 100644 --- a/src/common.h +++ b/src/common.h @@ -15,6 +15,7 @@ #include #include #include +#include #include #include "fallback.h" // IWYU pragma: keep diff --git a/src/complete.cpp b/src/complete.cpp index 3de8c81b1..3b9ae7f72 100644 --- a/src/complete.cpp +++ b/src/complete.cpp @@ -12,11 +12,13 @@ #include #include #include +#include #include #include #include #include #include +#include #include #include "autoload.h" diff --git a/src/env.cpp b/src/env.cpp index 106bed009..e1009196c 100644 --- a/src/env.cpp +++ b/src/env.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -189,7 +190,6 @@ void var_stack_t::pop() { assert(this->top && old_top && !old_top->next); assert(this->top != NULL); - var_table_t::iterator iter; for (const auto &entry_pair : old_top->env) { const var_entry_t &entry = entry_pair.second; if (entry.exportv) { diff --git a/src/env_universal_common.cpp b/src/env_universal_common.cpp index e0b5348a9..0047283cf 100644 --- a/src/env_universal_common.cpp +++ b/src/env_universal_common.cpp @@ -5,9 +5,16 @@ #include #include #include +// We need the sys/file.h for the flock() declaration on Linux but not OS X. +#include // IWYU pragma: keep +// We need the ioctl.h header so we can check if SIOCGIFHWADDR is defined by it so we know if we're +// on a Linux system. +#include // IWYU pragma: keep #include #include // IWYU pragma: keep +#if !defined(__APPLE__) && !defined(__CYGWIN__) #include +#endif #include #include #ifdef __CYGWIN__ @@ -18,16 +25,14 @@ #endif #include #include // IWYU pragma: keep -// We need the sys/file.h for the flock() declaration on Linux but not OS X. -#include // IWYU pragma: keep -// We need the ioctl.h header so we can check if SIOCGIFHWADDR is defined by it so we know if we're -// on a Linux system. -#include // IWYU pragma: keep +#include // IWYU pragma: keep + #include #include #include #include #include +#include #include #include "common.h" diff --git a/src/event.cpp b/src/event.cpp index daac533e8..2b0a68c8c 100644 --- a/src/event.cpp +++ b/src/event.cpp @@ -1,12 +1,14 @@ // Functions for handling event triggers. #include "config.h" // IWYU pragma: keep -#include #include #include + #include +#include #include #include +#include #include "common.h" #include "event.h" diff --git a/src/exec.cpp b/src/exec.cpp index f413e3936..9a8d68a38 100644 --- a/src/exec.cpp +++ b/src/exec.cpp @@ -7,21 +7,23 @@ #include #include #include -#include -#include -#include -#include -#include -#include -#ifdef HAVE_SPAWN_H -#include -#endif -#include -#include -#include #ifdef HAVE_SIGINFO_H #include #endif +#include +#ifdef HAVE_SPAWN_H +#include +#endif +#include +#include +#include + +#include +#include +#include +#include +#include +#include #include "builtin.h" #include "common.h" diff --git a/src/expand.cpp b/src/expand.cpp index c17f68882..a6bec6e0f 100644 --- a/src/expand.cpp +++ b/src/expand.cpp @@ -2,6 +2,7 @@ // IWYU pragma: no_include #include "config.h" +#include #include #include #include @@ -11,17 +12,13 @@ #include #include #include -#include #ifdef HAVE_SYS_SYSCTL_H #include // IWYU pragma: keep #endif -#include -#include #ifdef SunOS #include #endif #include -#include // IWYU pragma: keep #if __APPLE__ #include #else @@ -29,6 +26,12 @@ #include #endif +#include +#include +#include // IWYU pragma: keep +#include +#include + #include "common.h" #include "complete.h" #include "env.h" diff --git a/src/fish_tests.cpp b/src/fish_tests.cpp index a925c9ba5..7e945b7af 100644 --- a/src/fish_tests.cpp +++ b/src/fish_tests.cpp @@ -24,12 +24,15 @@ #include #include #include + #include #include #include +#include #include #include #include +#include #include #include "builtin.h" @@ -1653,9 +1656,9 @@ struct pager_layout_testcase_t { size_t width; const wchar_t *expected; - // Run ourselves as a test case - // Set our data on the pager, and then check the rendering - // We should have one line, and it should have our expected text + // Run ourselves as a test case. + // Set our data on the pager, and then check the rendering. + // We should have one line, and it should have our expected text. void run(pager_t &pager) const { pager.set_term_size(this->width, 24); page_rendering_t rendering = pager.render(); diff --git a/src/highlight.cpp b/src/highlight.cpp index ac5909613..70003facd 100644 --- a/src/highlight.cpp +++ b/src/highlight.cpp @@ -7,11 +7,13 @@ #include #include #include + #include #include #include #include #include +#include #include #include "builtin.h" diff --git a/src/highlight.h b/src/highlight.h index a63cb28dd..bffe6ba13 100644 --- a/src/highlight.h +++ b/src/highlight.h @@ -63,7 +63,6 @@ inline highlight_spec_t highlight_make_background(highlight_spec_t val) { } class history_item_t; -struct file_detection_context_t; /// Perform syntax highlighting for the shell commands in buff. The result is stored in the color /// array as a color_code from the HIGHLIGHT_ enum for each character in buff. diff --git a/src/history.cpp b/src/history.cpp index 28e89f2b6..73e511721 100644 --- a/src/history.cpp +++ b/src/history.cpp @@ -17,12 +17,15 @@ #include #include #include + #include #include #include +#include #include #include #include +#include #include "common.h" #include "env.h" diff --git a/src/input.cpp b/src/input.cpp index 17b5c6dcc..4bdd78544 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -1,6 +1,7 @@ // Functions for reading a character of input from stdin. #include "config.h" +#include #include #include #include diff --git a/src/input_common.cpp b/src/input_common.cpp index 3d44a7953..08a86534f 100644 --- a/src/input_common.cpp +++ b/src/input_common.cpp @@ -4,10 +4,6 @@ #include #include #include -#include -#include -#include -#include #ifdef HAVE_SYS_SELECT_H #include #endif @@ -16,7 +12,11 @@ #include #include #include + +#include +#include #include +#include #include "common.h" #include "env.h" diff --git a/src/intern.cpp b/src/intern.cpp index bd1f60124..2ca0340ac 100644 --- a/src/intern.cpp +++ b/src/intern.cpp @@ -1,7 +1,6 @@ // Library for pooling common strings. #include "config.h" // IWYU pragma: keep -#include #include #include #include diff --git a/src/iothread.cpp b/src/iothread.cpp index 5ec7f92e7..7ad527c72 100644 --- a/src/iothread.cpp +++ b/src/iothread.cpp @@ -2,7 +2,6 @@ #include #include -#include #include #include #include diff --git a/src/iothread.h b/src/iothread.h index b890c4430..8b29370c8 100644 --- a/src/iothread.h +++ b/src/iothread.h @@ -3,6 +3,7 @@ #define FISH_IOTHREAD_H #include +#include /// Runs a command on a thread. /// diff --git a/src/lru.h b/src/lru.h index d7632cec8..68b11c2aa 100644 --- a/src/lru.h +++ b/src/lru.h @@ -322,6 +322,7 @@ class lru_cache_t { // Count iterators size_t iter_dist = 0; for (const auto &p : *this) { + UNUSED(p); iter_dist++; } if (iter_dist != count) { diff --git a/src/pager.cpp b/src/pager.cpp index 70373b0af..d84f7913d 100644 --- a/src/pager.cpp +++ b/src/pager.cpp @@ -5,6 +5,8 @@ #include #include #include + +#include #include #include #include @@ -43,7 +45,7 @@ static size_t divide_round_up(size_t numer, size_t denom) { if (numer == 0) return 0; assert(denom > 0); - bool has_rem = (numer % denom) > 0; + bool has_rem = (numer % denom) != 0; return numer / denom + (has_rem ? 1 : 0); } @@ -368,9 +370,7 @@ void pager_t::set_completions(const completion_list_t &raw_completions) { void pager_t::set_prefix(const wcstring &pref) { prefix = pref; } -void pager_t::set_term_size(int w, int h) { - assert(w > 0); - assert(h > 0); +void pager_t::set_term_size(size_t w, size_t h) { available_term_width = w; available_term_height = h; } @@ -426,7 +426,6 @@ bool pager_t::completion_try_print(size_t cols, const wcstring &prefix, const co } bool print; - assert(cols >= 1); // Force fit if one column. if (cols == 1) { width_by_column[0] = std::min(width_by_column[0], term_width); diff --git a/src/pager.h b/src/pager.h index 74b9e9ce0..20c5bcf50 100644 --- a/src/pager.h +++ b/src/pager.h @@ -131,7 +131,7 @@ class pager_t { void set_prefix(const wcstring &pref); // Sets the terminal width and height. - void set_term_size(int w, int h); + void set_term_size(size_t w, size_t h); // Changes the selected completion in the given direction according to the layout of the given // rendering. Returns true if the selection changed. diff --git a/src/parse_execution.cpp b/src/parse_execution.cpp index 55110d885..7d65622d5 100644 --- a/src/parse_execution.cpp +++ b/src/parse_execution.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include "builtin.h" diff --git a/src/parse_tree.cpp b/src/parse_tree.cpp index eda099ac3..e6372f3a7 100644 --- a/src/parse_tree.cpp +++ b/src/parse_tree.cpp @@ -6,9 +6,10 @@ #include #include #include + #include -#include #include +#include #include #include "common.h" diff --git a/src/parse_util.cpp b/src/parse_util.cpp index f0a6177c8..98a0ec65b 100644 --- a/src/parse_util.cpp +++ b/src/parse_util.cpp @@ -9,8 +9,10 @@ #include #include #include + #include #include +#include #include "builtin.h" #include "common.h" diff --git a/src/parser.h b/src/parser.h index 4baec50b6..2ac09c7d2 100644 --- a/src/parser.h +++ b/src/parser.h @@ -3,7 +3,11 @@ #define FISH_PARSER_H #include + +#include #include +#include +#include #include #include "common.h" diff --git a/src/path.cpp b/src/path.cpp index 1aa0056ea..ae4be9618 100644 --- a/src/path.cpp +++ b/src/path.cpp @@ -12,6 +12,7 @@ #include #include +#include #include #include "common.h" diff --git a/src/proc.cpp b/src/proc.cpp index 4fcb07e7c..2641aff6c 100644 --- a/src/proc.cpp +++ b/src/proc.cpp @@ -7,7 +7,6 @@ #include "config.h" #include -#include #include #include #include diff --git a/src/proc.h b/src/proc.h index 8aa42f77d..ef2aaa759 100644 --- a/src/proc.h +++ b/src/proc.h @@ -11,7 +11,10 @@ #include // IWYU pragma: keep #include #include + #include +#include +#include #include "common.h" #include "io.h" diff --git a/src/reader.cpp b/src/reader.cpp index a12d2b189..1aac55357 100644 --- a/src/reader.cpp +++ b/src/reader.cpp @@ -37,6 +37,8 @@ #include #include +#include +#include #include #include @@ -791,13 +793,13 @@ void reader_init() { void reader_destroy() { pthread_key_delete(generation_count_key); } +/// Restore the term mode if we own the terminal. It's important we do this before +/// restore_foreground_process_group, otherwise we won't think we own the terminal. void restore_term_mode() { - // Restore the term mode if we own the terminal. It's important we do this before - // restore_foreground_process_group, otherwise we won't think we own the terminal. - if (getpid() == tcgetpgrp(STDIN_FILENO)) { - if (tcsetattr(STDIN_FILENO, TCSANOW, &terminal_mode_on_startup) == -1 && errno == EIO) { - redirect_tty_output(); - } + if (getpid() != tcgetpgrp(STDIN_FILENO)) return; + + if (tcsetattr(STDIN_FILENO, TCSANOW, &terminal_mode_on_startup) == -1 && errno == EIO) { + redirect_tty_output(); } } diff --git a/src/screen.h b/src/screen.h index 21622ba8f..3d515a2fb 100644 --- a/src/screen.h +++ b/src/screen.h @@ -12,7 +12,10 @@ #include #include #include +#include + #include +#include #include #include #include diff --git a/src/tokenizer.cpp b/src/tokenizer.cpp index d39e27bcb..5fecf7f2f 100644 --- a/src/tokenizer.cpp +++ b/src/tokenizer.cpp @@ -8,7 +8,9 @@ #include #include #include + #include +#include #include "common.h" #include "fallback.h" // IWYU pragma: keep diff --git a/src/wutil.cpp b/src/wutil.cpp index c989269cd..432fd597a 100644 --- a/src/wutil.cpp +++ b/src/wutil.cpp @@ -17,8 +17,8 @@ #include #include #include + #include -#include #include #include "common.h"