From 2a680ebd127f199a174f9c4b5745147f302e9e72 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sun, 26 Aug 2018 00:43:40 -0700 Subject: [PATCH] Fix some miscellaneous warnings --- src/builtin_string.cpp | 23 +++++++++++------------ src/history.cpp | 2 +- src/reader.cpp | 3 +-- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/builtin_string.cpp b/src/builtin_string.cpp index a0e02b82e..2f765e02c 100644 --- a/src/builtin_string.cpp +++ b/src/builtin_string.cpp @@ -907,18 +907,17 @@ class literal_replacer_t : public string_replacer_t { static wcstring interpret_escapes(const wcstring &arg) { wcstring result; - - const wchar_t *orig = arg.c_str(); - const wchar_t *start = arg.c_str(); - while (orig - start < arg.size()) { - if (*orig == L'\\') { - orig += read_unquoted_escape(orig, &result, true, false); + result.reserve(arg.size()); + const wchar_t *cursor = arg.c_str(); + const wchar_t *end = cursor + arg.size(); + while (cursor < end) { + if (*cursor == L'\\') { + cursor += read_unquoted_escape(cursor, &result, true, false); } else { - result += *orig; - orig++; + result.push_back(*cursor); + cursor++; } } - return result; } @@ -948,15 +947,15 @@ bool literal_replacer_t::replace_matches(const wcstring &arg) { } else { auto &cmp_func = opts.ignore_case ? wcsncasecmp : wcsncmp; const wchar_t *cur = arg.c_str(); - const wchar_t *start = arg.c_str(); - while (cur - start < arg.size()) { + const wchar_t *end = cur + arg.size(); + while (cur < end) { if ((opts.all || !replacement_occurred) && cmp_func(cur, pattern.c_str(), patlen) == 0) { result += replacement; cur += patlen; replacement_occurred = true; total_replaced++; } else { - result += *cur; + result.push_back(*cur); cur++; } } diff --git a/src/history.cpp b/src/history.cpp index 48fa97c4f..e49b4768c 100644 --- a/src/history.cpp +++ b/src/history.cpp @@ -299,7 +299,7 @@ class history_file_contents_t { static std::unique_ptr create(int fd) { // Check that the file is seekable, and its size. off_t len = lseek(fd, 0, SEEK_END); - if (len <= 0 || len >= SIZE_MAX) return nullptr; + if (len <= 0 || static_cast(len) >= SIZE_MAX) return nullptr; if (lseek(fd, 0, SEEK_SET) != 0) return nullptr; // Read the file, possibly ussing mmap. diff --git a/src/reader.cpp b/src/reader.cpp index bb7b4745d..e8d013f3d 100644 --- a/src/reader.cpp +++ b/src/reader.cpp @@ -278,8 +278,7 @@ class reader_history_search_t { bool add_skip(const wcstring &str) { return skips_.insert(str).second; } /// Reset, beginning a new line or token mode search. - void reset_to_mode(const wcstring &text, history_t *hist, mode_t mode, - wcstring_list_t skip_list = {}) { + void reset_to_mode(const wcstring &text, history_t *hist, mode_t mode) { assert(mode != inactive && "mode cannot be inactive in this setter"); skips_ = {text}; matches_ = {text};