aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Kurtis Rader <krader@skepticism.us>2016-05-28 22:28:26 -0700
committerGravatar Kurtis Rader <krader@skepticism.us>2016-05-29 22:24:29 -0700
commit5bf1b0e5f500b6b99a866da32dd9002219cac6d6 (patch)
tree4622863e7f28ad7f840d6a7096057286aee4e750 /src
parent3d19b549c8d9fc77597d0de95260e90f5dda2dae (diff)
fix random lint issues
This only eliminates errors reported by `make lint`. It shouldn't cause any functional changes. This change does remove several functions that are unused. It also removes the `desc_arr` variable which is both unused and out of date with reality.
Diffstat (limited to 'src')
-rw-r--r--src/autoload.cpp2
-rw-r--r--src/builtin.cpp6
-rw-r--r--src/builtin_commandline.cpp6
-rw-r--r--src/complete.cpp15
-rw-r--r--src/env.cpp4
-rw-r--r--src/env_universal_common.cpp5
-rw-r--r--src/expand.cpp11
-rw-r--r--src/expand.h3
-rw-r--r--src/fallback.cpp50
-rw-r--r--src/fallback.h13
-rw-r--r--src/fish_tests.cpp63
-rw-r--r--src/function.cpp26
-rw-r--r--src/highlight.cpp1
-rw-r--r--src/history.cpp21
-rw-r--r--src/input.cpp33
-rw-r--r--src/intern.cpp4
-rw-r--r--src/iothread.cpp15
-rw-r--r--src/kill.cpp3
-rw-r--r--src/output.cpp6
-rw-r--r--src/parse_tree.cpp10
-rw-r--r--src/parser.cpp11
-rw-r--r--src/parser.h6
-rw-r--r--src/proc.cpp60
-rw-r--r--src/signal.cpp2
-rw-r--r--src/util.cpp1
-rw-r--r--src/wutil.cpp2
26 files changed, 92 insertions, 287 deletions
diff --git a/src/autoload.cpp b/src/autoload.cpp
index 2d404cf9..9a8ebf40 100644
--- a/src/autoload.cpp
+++ b/src/autoload.cpp
@@ -86,7 +86,7 @@ int autoload_t::load(const wcstring &cmd, bool reload) {
this->last_path_tokenized.clear();
tokenize_variable_array(this->last_path, this->last_path_tokenized);
- scoped_lock locker(lock);
+ scoped_lock locker(lock); //!OCLINT(side-effect)
this->evict_all_nodes();
}
diff --git a/src/builtin.cpp b/src/builtin.cpp
index 336f09eb..b445cdf0 100644
--- a/src/builtin.cpp
+++ b/src/builtin.cpp
@@ -81,7 +81,7 @@
// The send stuff to foreground message.
#define FG_MSG _(L"Send job %d, '%ls' to foreground\n")
-/// Datastructure to describe a builtin.
+/// Data structure to describe a builtin.
struct builtin_data_t {
// Name of the builtin.
const wchar_t *name;
@@ -1807,9 +1807,7 @@ static int builtin_random(parser_t &parser, io_streams_t &streams, wchar_t **arg
srand48_r(time(0), &seed_buffer);
}
lrand48_r(&seed_buffer, &res);
- // The labs() shouldn't be necessary since lrand48 is supposed to
- // return only positive integers but we're going to play it safe.
- streams.out.append_format(L"%ld\n", labs(res % 32768));
+ streams.out.append_format(L"%ld\n", res % 32768);
break;
}
case 1: {
diff --git a/src/builtin_commandline.cpp b/src/builtin_commandline.cpp
index c25e6041..0a76ef84 100644
--- a/src/builtin_commandline.cpp
+++ b/src/builtin_commandline.cpp
@@ -67,7 +67,7 @@ static wcstring_list_t *get_transient_stack() {
static bool get_top_transient(wcstring *out_result) {
ASSERT_IS_MAIN_THREAD();
bool result = false;
- scoped_lock locker(transient_commandline_lock);
+ scoped_lock locker(transient_commandline_lock); //!OCLINT(side-effect)
const wcstring_list_t *stack = get_transient_stack();
if (!stack->empty()) {
out_result->assign(stack->back());
@@ -79,7 +79,7 @@ static bool get_top_transient(wcstring *out_result) {
builtin_commandline_scoped_transient_t::builtin_commandline_scoped_transient_t(
const wcstring &cmd) {
ASSERT_IS_MAIN_THREAD();
- scoped_lock locker(transient_commandline_lock);
+ scoped_lock locker(transient_commandline_lock); //!OCLINT(side-effect)
wcstring_list_t *stack = get_transient_stack();
stack->push_back(cmd);
this->token = stack->size();
@@ -87,7 +87,7 @@ builtin_commandline_scoped_transient_t::builtin_commandline_scoped_transient_t(
builtin_commandline_scoped_transient_t::~builtin_commandline_scoped_transient_t() {
ASSERT_IS_MAIN_THREAD();
- scoped_lock locker(transient_commandline_lock);
+ scoped_lock locker(transient_commandline_lock); //!OCLINT(side-effect)
wcstring_list_t *stack = get_transient_stack();
assert(this->token == stack->size());
stack->pop_back();
diff --git a/src/complete.cpp b/src/complete.cpp
index 59da5a94..6062a055 100644
--- a/src/complete.cpp
+++ b/src/complete.cpp
@@ -425,7 +425,7 @@ static completion_entry_t &complete_get_exact_entry(const wcstring &cmd, bool cm
void complete_set_authoritative(const wchar_t *cmd, bool cmd_is_path, bool authoritative) {
CHECK(cmd, );
- scoped_lock lock(completion_lock);
+ scoped_lock lock(completion_lock); //!OCLINT(has side effects)
completion_entry_t &c = complete_get_exact_entry(cmd, cmd_is_path);
c.authoritative = authoritative;
@@ -439,7 +439,7 @@ void complete_add(const wchar_t *cmd, bool cmd_is_path, const wcstring &option,
assert(option.empty() == (option_type == option_type_args_only));
// Lock the lock that allows us to edit the completion entry list.
- scoped_lock lock(completion_lock);
+ scoped_lock lock(completion_lock); //!OCLINT(has side effects)
completion_entry_t &c = complete_get_exact_entry(cmd, cmd_is_path);
@@ -476,7 +476,7 @@ bool completion_entry_t::remove_option(const wcstring &option, complete_option_t
void complete_remove(const wcstring &cmd, bool cmd_is_path, const wcstring &option,
complete_option_type_t type) {
- scoped_lock lock(completion_lock);
+ scoped_lock lock(completion_lock); //!OCLINT(has side effects)
completion_entry_t tmp_entry(cmd, cmd_is_path, false);
completion_entry_set_t::iterator iter = completion_set.find(tmp_entry);
@@ -493,7 +493,7 @@ void complete_remove(const wcstring &cmd, bool cmd_is_path, const wcstring &opti
}
void complete_remove_all(const wcstring &cmd, bool cmd_is_path) {
- scoped_lock lock(completion_lock);
+ scoped_lock lock(completion_lock); //!OCLINT(has side effects)
completion_entry_t tmp_entry(cmd, cmd_is_path, false);
completion_set.erase(tmp_entry);
@@ -1340,6 +1340,7 @@ void complete(const wcstring &cmd_with_subcmds, std::vector<completion_t> *out_c
}
}
+ // cppcheck-suppress nullPointerRedundantCheck
if (cmd_node && cmd_node->location_in_or_at_end_of_source_range(pos)) {
// Complete command filename.
completer.complete_cmd(current_token, use_function, use_builtin, use_command,
@@ -1478,7 +1479,7 @@ static void append_switch(wcstring &out, const wcstring &opt, const wcstring &ar
wcstring complete_print() {
wcstring out;
- scoped_lock locker(completion_lock);
+ scoped_lock locker(completion_lock); //!OCLINT(side-effect)
// Get a list of all completions in a vector, then sort it by order.
std::vector<const completion_entry_t *> all_completions;
@@ -1595,7 +1596,7 @@ wcstring_list_t complete_get_wrap_chain(const wcstring &command) {
if (command.empty()) {
return wcstring_list_t();
}
- scoped_lock locker(wrapper_lock);
+ scoped_lock locker(wrapper_lock); //!OCLINT(side-effect)
const wrapper_map_t &wraps = wrap_map();
wcstring_list_t result;
@@ -1631,7 +1632,7 @@ wcstring_list_t complete_get_wrap_chain(const wcstring &command) {
wcstring_list_t complete_get_wrap_pairs() {
wcstring_list_t result;
- scoped_lock locker(wrapper_lock);
+ scoped_lock locker(wrapper_lock); //!OCLINT(side-effect)
const wrapper_map_t &wraps = wrap_map();
for (wrapper_map_t::const_iterator outer = wraps.begin(); outer != wraps.end(); ++outer) {
const wcstring &cmd = outer->first;
diff --git a/src/env.cpp b/src/env.cpp
index 381b4588..e09064ad 100644
--- a/src/env.cpp
+++ b/src/env.cpp
@@ -699,7 +699,7 @@ env_var_t env_get_string(const wcstring &key, env_mode_flags_t mode) {
if (search_local || search_global) {
/* Lock around a local region */
- scoped_lock lock(env_lock);
+ scoped_lock lock(env_lock); //!OCLINT(has side effects)
env_node_t *env = search_local ? top : global_env;
@@ -869,7 +869,7 @@ static void add_key_to_string_set(const var_table_t &envs, std::set<wcstring> *s
}
wcstring_list_t env_get_names(int flags) {
- scoped_lock lock(env_lock);
+ scoped_lock lock(env_lock); //!OCLINT(has side effects)
wcstring_list_t result;
std::set<wcstring> names;
diff --git a/src/env_universal_common.cpp b/src/env_universal_common.cpp
index bb5b759b..c1b7c46c 100644
--- a/src/env_universal_common.cpp
+++ b/src/env_universal_common.cpp
@@ -14,6 +14,7 @@
#include <sys/mman.h>
#include <sys/socket.h>
#include <sys/stat.h>
+#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#include <wchar.h>
@@ -311,7 +312,7 @@ void env_universal_t::set_internal(const wcstring &key, const wcstring &val, boo
}
void env_universal_t::set(const wcstring &key, const wcstring &val, bool exportv) {
- scoped_lock locker(lock);
+ scoped_lock locker(lock); //!OCLINT(side-effect)
this->set_internal(key, val, exportv, true /* overwrite */);
}
@@ -331,7 +332,7 @@ bool env_universal_t::remove(const wcstring &key) {
wcstring_list_t env_universal_t::get_names(bool show_exported, bool show_unexported) const {
wcstring_list_t result;
- scoped_lock locker(lock);
+ scoped_lock locker(lock); //!OCLINT(side-effect)
var_table_t::const_iterator iter;
for (iter = vars.begin(); iter != vars.end(); ++iter) {
const wcstring &key = iter->first;
diff --git a/src/expand.cpp b/src/expand.cpp
index b69c79f8..5ea21a14 100644
--- a/src/expand.cpp
+++ b/src/expand.cpp
@@ -433,17 +433,6 @@ bool process_iterator_t::next_process(wcstring *out_str, pid_t *out_pid) {
#endif
-std::vector<wcstring> expand_get_all_process_names(void) {
- wcstring name;
- pid_t pid;
- process_iterator_t iterator;
- std::vector<wcstring> result;
- while (iterator.next_process(&name, &pid)) {
- result.push_back(name);
- }
- return result;
-}
-
// Helper function to do a job search.
struct find_job_data_t {
const wchar_t *proc; // the process to search for - possibly numeric, possibly a name
diff --git a/src/expand.h b/src/expand.h
index a0efd1fd..7c82d72e 100644
--- a/src/expand.h
+++ b/src/expand.h
@@ -144,9 +144,6 @@ void expand_tilde(wcstring &input);
/// Perform the opposite of tilde expansion on the string, which is modified in place.
wcstring replace_home_directory_with_tilde(const wcstring &str);
-/// Testing function for getting all process names.
-std::vector<wcstring> expand_get_all_process_names(void);
-
/// Abbreviation support. Expand src as an abbreviation, returning true if one was found, false if
/// not. If result is not-null, returns the abbreviation by reference.
#define USER_ABBREVIATIONS_VARIABLE_NAME L"fish_user_abbreviations"
diff --git a/src/fallback.cpp b/src/fallback.cpp
index b14b9243..9b746842 100644
--- a/src/fallback.cpp
+++ b/src/fallback.cpp
@@ -90,6 +90,7 @@ char *tparm_solaris_kludge(char *str, ...) {
#endif
+#if __APPLE__
/// Fallback implementations of wcsdup and wcscasecmp. On systems where these are not needed (e.g.
/// building on Linux) these should end up just being stripped, as they are static functions that
/// are not referenced in this file.
@@ -103,6 +104,7 @@ __attribute__((unused)) static wchar_t *wcsdup_fallback(const wchar_t *in) {
memcpy(out, in, sizeof(wchar_t) * (len + 1));
return out;
}
+#endif
__attribute__((unused)) static int wcscasecmp_fallback(const wchar_t *a, const wchar_t *b) {
if (*a == 0) {
@@ -168,54 +170,6 @@ wchar_t *wcsndup(const wchar_t *in, size_t c) {
}
#endif
-#ifndef HAVE_WCSLCAT
-
-/*$OpenBSD: strlcat.c,v 1.11 2003/06/17 21:56:24 millert Exp $*/
-
-/*
- * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-size_t wcslcat(wchar_t *dst, const wchar_t *src, size_t siz) {
- register wchar_t *d = dst;
- register const wchar_t *s = src;
- register size_t n = siz;
- size_t dlen;
-
- // Find the end of dst and adjust bytes left but don't go past end.
- while (n-- != 0 && *d != '\0') d++;
-
- dlen = d - dst;
- n = siz - dlen;
-
- if (n == 0) return dlen + wcslen(s);
-
- while (*s != '\0') {
- if (n != 1) {
- *d++ = *s;
- n--;
- }
- s++;
- }
- *d = '\0';
-
- return dlen + (s - src);
- /* count does not include NUL */
-}
-
-#endif
#ifndef HAVE_WCSLCPY
/*$OpenBSD: strlcpy.c,v 1.8 2003/06/17 21:56:24 millert Exp $*/
diff --git a/src/fallback.h b/src/fallback.h
index f167ff69..09e30142 100644
--- a/src/fallback.h
+++ b/src/fallback.h
@@ -7,7 +7,6 @@
// compiling several modules that include this header because they use symbols which are defined as
// macros in <term.h>.
// IWYU pragma: no_include <term.h>
-#include <signal.h>
#include <stdint.h>
#include <unistd.h>
// The following include must be kept despite what IWYU says. That's because of the interaction
@@ -83,16 +82,6 @@ wchar_t *wcsndup(const wchar_t *in, size_t c);
wchar_t *wcsndup(const wchar_t *in, size_t c);
#endif
-#ifndef HAVE_WCSLCAT
-/// Appends src to string dst of size siz (unlike wcsncat, siz is the full size of dst, not space
-/// left). At most siz-1 characters will be copied. Always NUL terminates (unless siz <=
-/// wcslen(dst)). Returns wcslen(src) + MIN(siz, wcslen(initial dst)). If retval >= siz,
-/// truncation occurred.
-///
-/// This is the OpenBSD strlcat function, modified for wide characters, and renamed to reflect this
-/// change.
-size_t wcslcat(wchar_t *dst, const wchar_t *src, size_t siz);
-#endif
#ifndef HAVE_WCSLCPY
/// Copy src to string dst of size siz. At most siz-1 characters will be copied. Always NUL
/// terminates (unless siz == 0). Returns wcslen(src); if retval >= siz, truncation occurred.
@@ -103,7 +92,7 @@ size_t wcslcpy(wchar_t *dst, const wchar_t *src, size_t siz);
#endif
#ifndef HAVE_LRAND48_R
-/// Datastructure for the lrand48_r fallback implementation.
+/// Data structure for the lrand48_r fallback implementation.
struct drand48_data {
unsigned int seed;
};
diff --git a/src/fish_tests.cpp b/src/fish_tests.cpp
index 49c9327b..29040e22 100644
--- a/src/fish_tests.cpp
+++ b/src/fish_tests.cpp
@@ -15,6 +15,7 @@
#include <stdlib.h>
#include <string.h>
#include <sys/select.h>
+#include <sys/time.h>
#include <sys/types.h>
#include <sys/utsname.h>
#include <sys/wait.h>
@@ -60,7 +61,6 @@
#include "signal.h"
#include "tokenizer.h"
#include "utf8.h"
-#include "util.h"
#include "wcstringutil.h"
#include "wildcard.h"
#include "wutil.h" // IWYU pragma: keep
@@ -2194,62 +2194,6 @@ static void test_autosuggestion_combining() {
do_test(combine_command_and_autosuggestion(L"alpha", L"ALPHA") == L"alpha");
}
-/// Test speed of completion calculations.
-void perf_complete() {
- wchar_t c;
- std::vector<completion_t> out;
- long long t1, t2;
- int matches = 0;
- double t;
- wchar_t str[3] = {0, 0, 0};
- int i;
-
- say(L"Testing completion performance");
-
- reader_push(L"");
- say(L"Here we go");
-
- t1 = get_time();
-
- for (c = L'a'; c <= L'z'; c++) {
- str[0] = c;
- reader_set_buffer(str, 0);
-
- complete(str, &out, COMPLETION_REQUEST_DEFAULT, env_vars_snapshot_t::current());
-
- matches += out.size();
- out.clear();
- }
- t2 = get_time();
-
- t = (double)(t2 - t1) / (1000000 * 26);
-
- say(L"One letter command completion took %f seconds per completion, %f microseconds/match", t,
- (double)(t2 - t1) / matches);
-
- matches = 0;
- t1 = get_time();
- for (i = 0; i < LAPS; i++) {
- str[0] = 'a' + (rand() % 26);
- str[1] = 'a' + (rand() % 26);
-
- reader_set_buffer(str, 0);
-
- complete(str, &out, COMPLETION_REQUEST_DEFAULT, env_vars_snapshot_t::current());
-
- matches += out.size();
- out.clear();
- }
- t2 = get_time();
-
- t = (double)(t2 - t1) / (1000000 * LAPS);
-
- say(L"Two letter command completion took %f seconds per completion, %f microseconds/match", t,
- (double)(t2 - t1) / matches);
-
- reader_pop();
-}
-
static void test_history_matches(history_search_t &search, size_t matches) {
size_t i;
for (i = 0; i < matches; i++) {
@@ -3937,11 +3881,6 @@ int main(int argc, char **argv) {
say(L"Encountered %d errors in low-level tests", err_count);
if (s_test_run_count == 0) say(L"*** No Tests Were Actually Run! ***");
- // Skip performance tests for now, since they seem to hang when running from inside make.
-
- // say( L"Testing performance" );
- // perf_complete();
-
reader_destroy();
builtin_destroy();
event_destroy();
diff --git a/src/function.cpp b/src/function.cpp
index fc397472..21f7d963 100644
--- a/src/function.cpp
+++ b/src/function.cpp
@@ -63,7 +63,7 @@ static bool is_autoload = false;
/// loaded.
static int load(const wcstring &name) {
ASSERT_IS_MAIN_THREAD();
- scoped_lock lock(functions_lock);
+ scoped_lock lock(functions_lock); //!OCLINT(has side effects)
bool was_autoload = is_autoload;
int res;
@@ -163,7 +163,7 @@ void function_add(const function_data_t &data, const parser_t &parser, int defin
CHECK(!data.name.empty(), );
CHECK(data.definition, );
- scoped_lock lock(functions_lock);
+ scoped_lock lock(functions_lock); //!OCLINT(has side effects)
// Remove the old function.
function_remove(data.name);
@@ -184,21 +184,21 @@ void function_add(const function_data_t &data, const parser_t &parser, int defin
int function_exists(const wcstring &cmd) {
if (parser_keywords_is_reserved(cmd)) return 0;
- scoped_lock lock(functions_lock);
+ scoped_lock lock(functions_lock); //!OCLINT(has side effects)
load(cmd);
return loaded_functions.find(cmd) != loaded_functions.end();
}
void function_load(const wcstring &cmd) {
if (!parser_keywords_is_reserved(cmd)) {
- scoped_lock lock(functions_lock);
+ scoped_lock lock(functions_lock); //!OCLINT(has side effects)
load(cmd);
}
}
int function_exists_no_autoload(const wcstring &cmd, const env_vars_snapshot_t &vars) {
if (parser_keywords_is_reserved(cmd)) return 0;
- scoped_lock lock(functions_lock);
+ scoped_lock lock(functions_lock); //!OCLINT(has side effects)
return loaded_functions.find(cmd) != loaded_functions.end() ||
function_autoloader.can_load(cmd, vars);
}
@@ -248,25 +248,25 @@ bool function_get_definition(const wcstring &name, wcstring *out_definition) {
}
wcstring_list_t function_get_named_arguments(const wcstring &name) {
- scoped_lock lock(functions_lock);
+ scoped_lock lock(functions_lock); //!OCLINT(has side effects)
const function_info_t *func = function_get(name);
return func ? func->named_arguments : wcstring_list_t();
}
std::map<wcstring, env_var_t> function_get_inherit_vars(const wcstring &name) {
- scoped_lock lock(functions_lock);
+ scoped_lock lock(functions_lock); //!OCLINT(has side effects)
const function_info_t *func = function_get(name);
return func ? func->inherit_vars : std::map<wcstring, env_var_t>();
}
int function_get_shadow_builtin(const wcstring &name) {
- scoped_lock lock(functions_lock);
+ scoped_lock lock(functions_lock); //!OCLINT(has side effects)
const function_info_t *func = function_get(name);
return func ? func->shadow_builtin : false;
}
int function_get_shadow_scope(const wcstring &name) {
- scoped_lock lock(functions_lock);
+ scoped_lock lock(functions_lock); //!OCLINT(has side effects)
const function_info_t *func = function_get(name);
return func ? func->shadow_scope : false;
}
@@ -285,7 +285,7 @@ bool function_get_desc(const wcstring &name, wcstring *out_desc) {
void function_set_desc(const wcstring &name, const wcstring &desc) {
load(name);
- scoped_lock lock(functions_lock);
+ scoped_lock lock(functions_lock); //!OCLINT(has side effects)
function_map_t::iterator iter = loaded_functions.find(name);
if (iter != loaded_functions.end()) {
iter->second.description = desc;
@@ -309,7 +309,7 @@ bool function_copy(const wcstring &name, const wcstring &new_name) {
wcstring_list_t function_get_names(int get_hidden) {
std::set<wcstring> names;
- scoped_lock lock(functions_lock);
+ scoped_lock lock(functions_lock); //!OCLINT(has side effects)
autoload_names(names, get_hidden);
function_map_t::const_iterator iter;
@@ -326,13 +326,13 @@ wcstring_list_t function_get_names(int get_hidden) {
}
const wchar_t *function_get_definition_file(const wcstring &name) {
- scoped_lock lock(functions_lock);
+ scoped_lock lock(functions_lock); //!OCLINT(has side effects)
const function_info_t *func = function_get(name);
return func ? func->definition_file : NULL;
}
int function_get_definition_offset(const wcstring &name) {
- scoped_lock lock(functions_lock);
+ scoped_lock lock(functions_lock); //!OCLINT(has side effects)
const function_info_t *func = function_get(name);
return func ? func->definition_offset : -1;
}
diff --git a/src/highlight.cpp b/src/highlight.cpp
index 9dd6b224..49dd2f06 100644
--- a/src/highlight.cpp
+++ b/src/highlight.cpp
@@ -1039,6 +1039,7 @@ const highlighter_t::color_array_t &highlighter_t::highlight() {
std::fill(this->color_array.begin(), this->color_array.end(), 0);
#if 0
+ // Disabled for the 2.2.0 release: https://github.com/fish-shell/fish-shell/issues/1809.
const wcstring dump = parse_dump_tree(parse_tree, buff);
fprintf(stderr, "%ls\n", dump.c_str());
#endif
diff --git a/src/history.cpp b/src/history.cpp
index e849fb87..49ed1b67 100644
--- a/src/history.cpp
+++ b/src/history.cpp
@@ -661,22 +661,11 @@ static size_t offset_of_next_item_fish_1_x(const char *begin, size_t mmap_length
static size_t offset_of_next_item(const char *begin, size_t mmap_length,
history_file_type_t mmap_type, size_t *inout_cursor,
time_t cutoff_timestamp) {
- size_t result;
- switch (mmap_type) {
- case history_type_fish_2_0: {
- result =
- offset_of_next_item_fish_2_0(begin, mmap_length, inout_cursor, cutoff_timestamp);
- break;
- }
- case history_type_fish_1_x: {
- result = offset_of_next_item_fish_1_x(begin, mmap_length, inout_cursor);
- break;
- }
- case history_type_unknown: {
- // Oh well.
- result = (size_t)-1;
- break;
- }
+ size_t result = (size_t)-1;
+ if (mmap_type == history_type_fish_2_0) {
+ result = offset_of_next_item_fish_2_0(begin, mmap_length, inout_cursor, cutoff_timestamp);
+ } else if (mmap_type == history_type_fish_1_x) {
+ result = offset_of_next_item_fish_1_x(begin, mmap_length, inout_cursor);
}
return result;
}
diff --git a/src/input.cpp b/src/input.cpp
index efe2f594..5b599e85 100644
--- a/src/input.cpp
+++ b/src/input.cpp
@@ -131,39 +131,6 @@ wcstring describe_char(wint_t c) {
return format_string(L"%02x", c);
}
-/// Description of each supported input function.
-static const wchar_t *desc_arr[] = {
- L"Move to beginning of line",
- L"Move to end of line",
- L"Move forward one character",
- L"Move backward one character",
- L"Move forward one word",
- L"Move backward one word",
- L"Search backward through list of previous commands",
- L"Search forward through list of previous commands",
- L"Delete one character forward",
- L"Delete one character backward",
- L"Move contents from cursor to end of line to killring",
- L"Paste contents of killring",
- L"Rotate to previous killring entry",
- L"Guess the rest of the next input token",
- L"Move to first item of history",
- L"Move to last item of history",
- L"Clear current line",
- L"Move contents from beginning of line to cursor to killring",
- L"Move entire line to killring",
- L"Move next word to killring",
- L"Move previous word to killring",
- L"Write out key bindings",
- L"Clear entire screen",
- L"Quit the running program",
- L"Search backward through list of previous commands for matching token",
- L"Search forward through list of previous commands for matching token",
- L"Insert the pressed key",
- L"Do nothing",
- L"End of file",
- L"Repeat command"};
-
/// Internal code for each supported input function.
static const wchar_t code_arr[] = {R_BEGINNING_OF_LINE,
R_END_OF_LINE,
diff --git a/src/intern.cpp b/src/intern.cpp
index d92b142a..9030ef8a 100644
--- a/src/intern.cpp
+++ b/src/intern.cpp
@@ -38,8 +38,8 @@ static pthread_mutex_t intern_lock = PTHREAD_MUTEX_INITIALIZER;
static const wchar_t *intern_with_dup(const wchar_t *in, bool dup) {
if (!in) return NULL;
- // debug( 0, L"intern %ls", in );
- scoped_lock lock(intern_lock);
+ debug(5, L"intern %ls", in);
+ scoped_lock lock(intern_lock); //!OCLINT(has side effects)
const wchar_t *result;
#if USE_SET
diff --git a/src/iothread.cpp b/src/iothread.cpp
index 2780cda5..be08e451 100644
--- a/src/iothread.cpp
+++ b/src/iothread.cpp
@@ -8,6 +8,7 @@
#include <stdbool.h>
#include <stdio.h>
#include <sys/select.h>
+#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#include <queue>
@@ -107,7 +108,7 @@ static SpawnRequest_t *dequeue_spawn_request(void) {
}
static void enqueue_thread_result(SpawnRequest_t *req) {
- scoped_lock lock(s_result_queue_lock);
+ scoped_lock lock(s_result_queue_lock); //!OCLINT(has side effects)
s_result_queue.push(req);
}
@@ -195,7 +196,7 @@ int iothread_perform_base(int (*handler)(void *), void (*completionCallback)(voi
{
// Lock around a local region. Note that we can only access s_active_thread_count under the
// lock.
- scoped_lock lock(s_spawn_queue_lock);
+ scoped_lock lock(s_spawn_queue_lock); //!OCLINT(has side effects)
add_to_queue(req);
if (s_active_thread_count < IO_MAX_THREADS) {
s_active_thread_count++;
@@ -293,7 +294,7 @@ static void iothread_service_main_thread_requests(void) {
// Move the queue to a local variable.
std::queue<MainThreadRequest_t *> request_queue;
{
- scoped_lock queue_lock(s_main_thread_request_queue_lock);
+ scoped_lock queue_lock(s_main_thread_request_queue_lock); //!OCLINT(has side effects)
std::swap(request_queue, s_main_thread_request_queue);
}
@@ -316,7 +317,7 @@ static void iothread_service_main_thread_requests(void) {
//
// Because the waiting thread performs step 1 under the lock, if we take the lock, we avoid
// posting before the waiting thread is waiting.
- scoped_lock broadcast_lock(s_main_thread_performer_lock);
+ scoped_lock broadcast_lock(s_main_thread_performer_lock); //!OCLINT(has side effects)
VOMIT_ON_FAILURE(pthread_cond_broadcast(&s_main_thread_performer_condition));
}
}
@@ -326,7 +327,7 @@ static void iothread_service_result_queue() {
// Move the queue to a local variable.
std::queue<SpawnRequest_t *> result_queue;
{
- scoped_lock queue_lock(s_result_queue_lock);
+ scoped_lock queue_lock(s_result_queue_lock); //!OCLINT(has side effects)
std::swap(result_queue, s_result_queue);
}
@@ -357,7 +358,7 @@ int iothread_perform_on_main_base(int (*handler)(void *), void *context) {
// Append it. Do not delete the nested scope as it is crucial to the proper functioning of this
// code by virtue of the lock management.
{
- scoped_lock queue_lock(s_main_thread_request_queue_lock);
+ scoped_lock queue_lock(s_main_thread_request_queue_lock); //!OCLINT(has side effects)
s_main_thread_request_queue.push(&req);
}
@@ -366,7 +367,7 @@ int iothread_perform_on_main_base(int (*handler)(void *), void *context) {
VOMIT_ON_FAILURE(!write_loop(s_write_pipe, &wakeup_byte, sizeof wakeup_byte));
// Wait on the condition, until we're done.
- scoped_lock perform_lock(s_main_thread_performer_lock);
+ scoped_lock perform_lock(s_main_thread_performer_lock); //!OCLINT(has side effects)
while (!req.done) {
// It would be nice to support checking for cancellation here, but the clients need a
// deterministic way to clean up to avoid leaks
diff --git a/src/kill.cpp b/src/kill.cpp
index 706b1815..40dc5ece 100644
--- a/src/kill.cpp
+++ b/src/kill.cpp
@@ -4,7 +4,6 @@
// previous cuts.
#include "config.h" // IWYU pragma: keep
-#include <stdbool.h>
#include <stddef.h>
#include <algorithm>
#include <list>
@@ -13,8 +12,6 @@
#include "common.h"
#include "fallback.h" // IWYU pragma: keep
-#include "kill.h"
-#include "path.h"
/** Kill ring */
typedef std::list<wcstring> kill_list_t;
diff --git a/src/output.cpp b/src/output.cpp
index 78ea210b..0d7c74f0 100644
--- a/src/output.cpp
+++ b/src/output.cpp
@@ -31,7 +31,7 @@
static int writeb_internal(char c);
/// The function used for output.
-static int (*out)(char c) = &writeb_internal;
+static int (*out)(char c) = writeb_internal;
/// Name of terminal.
static wcstring current_term;
@@ -119,7 +119,7 @@ void write_color(rgb_color_t color, bool is_fg) {
// Background: ^[48;2;<r>;<g>;<b>m
color24_t rgb = color.to_color24();
char buff[128];
- snprintf(buff, sizeof buff, "\x1b[%u;2;%u;%u;%um", is_fg ? 38 : 48, rgb.rgb[0], rgb.rgb[1],
+ snprintf(buff, sizeof buff, "\x1b[%d;2;%u;%u;%um", is_fg ? 38 : 48, rgb.rgb[0], rgb.rgb[1],
rgb.rgb[2]);
int (*writer)(char) = output_get_writer();
if (writer) {
@@ -263,7 +263,7 @@ void set_color(rgb_color_t c, rgb_color_t c2) {
}
/// Default output method, simply calls write() on stdout.
-static int writeb_internal(char c) {
+static int writeb_internal(char c) { // cppcheck
write_loop(1, &c, 1);
return 0;
}
diff --git a/src/parse_tree.cpp b/src/parse_tree.cpp
index befa104b..e5666f83 100644
--- a/src/parse_tree.cpp
+++ b/src/parse_tree.cpp
@@ -335,7 +335,10 @@ static inline parse_token_type_t parse_token_type_from_tokenizer_token(
return result;
}
-/// Helper function for dump_tree.
+#if 0
+// Disabled for the 2.2.0 release: https://github.com/fish-shell/fish-shell/issues/1809.
+
+/// Helper function for parse_dump_tree().
static void dump_tree_recursive(const parse_node_tree_t &nodes, const wcstring &src,
node_offset_t node_idx, size_t indent, wcstring *result,
size_t *line, node_offset_t *inout_first_node_not_dumped) {
@@ -411,6 +414,7 @@ wcstring parse_dump_tree(const parse_node_tree_t &nodes, const wcstring &src) {
}
return result;
}
+#endif
/// Struct representing elements of the symbol stack, used in the internal state of the LL parser.
struct parse_stack_element_t {
@@ -467,7 +471,7 @@ class parse_ll_t {
// failure (e.g. it is not an unclosed block).
bool report_error_for_unclosed_block();
- void dump_stack(void) const;
+ // void dump_stack(void) const;
/// Get the node corresponding to the top element of the stack.
parse_node_t &node_for_top_symbol() {
@@ -586,6 +590,7 @@ class parse_ll_t {
void acquire_output(parse_node_tree_t *output, parse_error_list_t *errors);
};
+#if 0
void parse_ll_t::dump_stack(void) const {
// Walk backwards from the top, looking for parents.
wcstring_list_t lines;
@@ -609,6 +614,7 @@ void parse_ll_t::dump_stack(void) const {
fprintf(stderr, " %ls\n", lines.at(idx).c_str());
}
}
+#endif
// Give each node a source range equal to the union of the ranges of its children. Terminal nodes
// already have source ranges (and no children). Since children always appear after their parents,
diff --git a/src/parser.cpp b/src/parser.cpp
index 90211df1..86026f80 100644
--- a/src/parser.cpp
+++ b/src/parser.cpp
@@ -75,7 +75,7 @@ class io_chain_t;
/// Unknown block description.
#define UNKNOWN_BLOCK N_(L"unknown/invalid block")
-/// Datastructure to describe a block type, like while blocks, command substitution blocks, etc.
+/// Data structure to describe a block type, like while blocks, command substitution blocks, etc.
struct block_lookup_entry {
// The block type id. The legal values are defined in parser.h.
block_type_t type;
@@ -225,6 +225,8 @@ const wchar_t *parser_t::get_block_desc(int block) const {
return _(UNKNOWN_BLOCK);
}
+#if 0
+// TODO: Lint says this isn't used (which is true). Should this be removed?
wcstring parser_t::block_stack_description() const {
wcstring result;
size_t idx = this->block_count();
@@ -241,6 +243,7 @@ wcstring parser_t::block_stack_description() const {
}
return result;
}
+#endif
const block_t *parser_t::block_at_index(size_t idx) const {
// Zero corresponds to the last element in our vector.
@@ -253,11 +256,7 @@ block_t *parser_t::block_at_index(size_t idx) {
return idx < count ? block_stack.at(count - idx - 1) : NULL;
}
-const block_t *parser_t::current_block() const {
- return block_stack.empty() ? NULL : block_stack.back();
-}
-
-block_t *parser_t::current_block() { return block_stack.empty() ? NULL : block_stack.back(); }
+block_t *const parser_t::current_block() { return block_stack.empty() ? NULL : block_stack.back(); }
void parser_t::forbid_function(const wcstring &function) { forbidden_function.push_back(function); }
diff --git a/src/parser.h b/src/parser.h
index 4a682306..d3fd8803 100644
--- a/src/parser.h
+++ b/src/parser.h
@@ -193,8 +193,11 @@ class parser_t {
/// The list of blocks, allocated with new. It's our responsibility to delete these.
std::vector<block_t *> block_stack;
+#if 0
+// TODO: Lint says this isn't used (which is true). Should this be removed?
/// Gets a description of the block stack, for debugging.
wcstring block_stack_description() const;
+#endif
/// List of profile items, allocated with new.
std::vector<profile_item_t *> profile_items;
@@ -269,8 +272,7 @@ class parser_t {
block_t *block_at_index(size_t idx);
/// Returns the current (innermost) block.
- const block_t *current_block() const;
- block_t *current_block();
+ block_t *const current_block();
/// Count of blocks.
size_t block_count() const { return block_stack.size(); }
diff --git a/src/proc.cpp b/src/proc.cpp
index 1a298b21..ec1d86d5 100644
--- a/src/proc.cpp
+++ b/src/proc.cpp
@@ -167,7 +167,7 @@ static pthread_mutex_t job_id_lock = PTHREAD_MUTEX_INITIALIZER;
static std::vector<bool> consumed_job_ids;
job_id_t acquire_job_id(void) {
- scoped_lock lock(job_id_lock);
+ scoped_lock lock(job_id_lock); //!OCLINT(has side effects)
// Find the index of the first 0 slot.
std::vector<bool>::iterator slot =
@@ -186,7 +186,7 @@ job_id_t acquire_job_id(void) {
void release_job_id(job_id_t jid) {
assert(jid > 0);
- scoped_lock lock(job_id_lock);
+ scoped_lock lock(job_id_lock); //!OCLINT(has side effects)
size_t slot = (size_t)(jid - 1), count = consumed_job_ids.size();
// Make sure this slot is within our vector and is currently set to consumed.
@@ -649,61 +649,35 @@ int job_reap(bool interactive) {
/// Get the CPU time for the specified process.
unsigned long proc_get_jiffies(process_t *p) {
- wchar_t fn[FN_SIZE];
+ if (p->pid <= 0) return 0;
+ wchar_t fn[FN_SIZE];
char state;
int pid, ppid, pgrp, session, tty_nr, tpgid, exit_signal, processor;
-
long int cutime, cstime, priority, nice, placeholder, itrealvalue, rss;
unsigned long int flags, minflt, cminflt, majflt, cmajflt, utime, stime, starttime, vsize, rlim,
startcode, endcode, startstack, kstkesp, kstkeip, signal, blocked, sigignore, sigcatch,
wchan, nswap, cnswap;
char comm[1024];
- if (p->pid <= 0) return 0;
-
swprintf(fn, FN_SIZE, L"/proc/%d/stat", p->pid);
-
FILE *f = wfopen(fn, "r");
if (!f) return 0;
- int count = fscanf(
- f,
- "%d %s %c "
- "%d %d %d "
- "%d %d %lu "
-
- "%lu %lu %lu "
- "%lu %lu %lu "
- "%ld %ld %ld "
-
- "%ld %ld %ld "
- "%lu %lu %ld "
- "%lu %lu %lu "
-
- "%lu %lu %lu "
- "%lu %lu %lu "
- "%lu %lu %lu "
-
- "%lu %d %d ",
-
- &pid, comm, &state, &ppid, &pgrp, &session, &tty_nr, &tpgid, &flags,
-
- &minflt, &cminflt, &majflt, &cmajflt, &utime, &stime, &cutime, &cstime, &priority,
-
- &nice, &placeholder, &itrealvalue, &starttime, &vsize, &rss, &rlim, &startcode, &endcode,
-
- &startstack, &kstkesp, &kstkeip, &signal, &blocked, &sigignore, &sigcatch, &wchan, &nswap,
-
- &cnswap, &exit_signal, &processor);
-
- // Don't need to check exit status of fclose on read-only streams.
+ // TODO: replace the use of fscanf() as it is brittle and should never be used.
+ int count = fscanf(f,
+ "%9d %1023s %c %9d %9d %9d %9d %9d %9lu "
+ "%9lu %9lu %9lu %9lu %9lu %9lu %9ld %9ld %9ld "
+ "%9ld %9ld %9ld %9lu %9lu %9ld %9lu %9lu %9lu "
+ "%9lu %9lu %9lu %9lu %9lu %9lu %9lu %9lu %9lu "
+ "%9lu %9d %9d ",
+ &pid, comm, &state, &ppid, &pgrp, &session, &tty_nr, &tpgid, &flags, &minflt,
+ &cminflt, &majflt, &cmajflt, &utime, &stime, &cutime, &cstime, &priority,
+ &nice, &placeholder, &itrealvalue, &starttime, &vsize, &rss, &rlim,
+ &startcode, &endcode, &startstack, &kstkesp, &kstkeip, &signal, &blocked,
+ &sigignore, &sigcatch, &wchan, &nswap, &cnswap, &exit_signal, &processor);
fclose(f);
-
- if (count < 17) {
- return 0;
- }
-
+ if (count < 17) return 0;
return utime + stime + cutime + cstime;
}
diff --git a/src/signal.cpp b/src/signal.cpp
index 8aa55828..60066d3d 100644
--- a/src/signal.cpp
+++ b/src/signal.cpp
@@ -198,11 +198,13 @@ static void default_handler(int signal, siginfo_t *info, void *context) {
}
}
+#ifdef SIGWINCH
/// Respond to a winch signal by checking the terminal size.
static void handle_winch(int sig, siginfo_t *info, void *context) {
common_handle_winch(sig);
default_handler(sig, 0, 0);
}
+#endif
/// Respond to a hup signal by exiting, unless it is caught by a shellscript function, in which case
/// we do nothing.
diff --git a/src/util.cpp b/src/util.cpp
index bf44feab..f1333480 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -6,7 +6,6 @@
#include <errno.h>
#include <stdlib.h>
#include <sys/time.h>
-#include <sys/types.h>
#include <wchar.h>
#include <wctype.h>
diff --git a/src/wutil.cpp b/src/wutil.cpp
index 3b0bdb2e..02e975b2 100644
--- a/src/wutil.cpp
+++ b/src/wutil.cpp
@@ -415,7 +415,7 @@ const wchar_t *wgettext(const wchar_t *in) {
wgettext_init_if_necessary();
wcstring key = in;
- scoped_lock lock(wgettext_lock);
+ scoped_lock lock(wgettext_lock); //!OCLINT(has side effects)
wcstring &val = wgettext_map[key];
if (val.empty()) {