From: Erik Johansson Date: Sun, 23 Feb 2020 20:56:59 +0000 (+0100) Subject: Fix four minor cppcheck warnings X-Git-Tag: v4.0~586^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=eb4db0faecad11d487dd78dabdf86bdcfb87c46d;p=thirdparty%2Fccache.git Fix four minor cppcheck warnings - uninitvar:src/ccache.cpp:3422: Uninitialized variable: ctx - redundantInitialization:src/legacy_util.cpp:1067: Redundant initialization for 'q'. The initialized value is overwritten before it is read. - constVariable:src/stats.cpp:429: Variable 'ctx' can be declared with const - variableScope:src/Util.cpp:404: The scope of the variable 'right' can be reduced. --- diff --git a/src/Util.cpp b/src/Util.cpp index abca1d34f..dff944d84 100644 --- a/src/Util.cpp +++ b/src/Util.cpp @@ -401,13 +401,12 @@ normalize_absolute_path(string_view path) std::string result = "/"; const size_t npos = string_view::npos; size_t left = 1; - size_t right = 1; while (true) { if (left >= path.length()) { break; } - right = path.find('/', left); + const auto right = path.find('/', left); string_view part = path.substr(left, right == npos ? npos : right - left); if (part == "..") { if (result.length() > 1) { diff --git a/src/ccache.cpp b/src/ccache.cpp index a1fa6a42d..9f44a6557 100644 --- a/src/ccache.cpp +++ b/src/ccache.cpp @@ -3399,7 +3399,7 @@ initialize(int argc, char* argv[]) { // This object is placed onto the heap so it is available in exit functions // which run after main(). It is cleaned up by the last exit function. - Context* ctx = new Context{}; + Context* ctx = new Context; set_up_config(ctx->config); diff --git a/src/legacy_util.cpp b/src/legacy_util.cpp index e003bbf69..ef46e5415 100644 --- a/src/legacy_util.cpp +++ b/src/legacy_util.cpp @@ -977,7 +977,7 @@ subst_env_in_string(const char* str, char** errmsg) char* result = x_strdup(""); const char* p = str; // Interval start. const char* q = str; // Interval end. - for (q = str; *q; ++q) { + for (; *q; ++q) { if (*q == '$') { reformat(&result, "%s%.*s", result, (int)(q - p), p); if (!expand_variable(&q, &result, errmsg)) { diff --git a/src/stats.cpp b/src/stats.cpp index df093d708..ebfccbeda 100644 --- a/src/stats.cpp +++ b/src/stats.cpp @@ -426,7 +426,7 @@ stats_flush_to_file(const Config& config, void stats_flush(void* context) { - Context& ctx = *static_cast(context); + const Context& ctx = *static_cast(context); stats_flush_to_file(ctx.config, ctx.stats_file, ctx.counter_updates); }