]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Fix four minor cppcheck warnings 544/head
authorErik Johansson <erik@ejohansson.se>
Sun, 23 Feb 2020 20:56:59 +0000 (21:56 +0100)
committerErik Johansson <erik@ejohansson.se>
Sun, 23 Feb 2020 21:22:07 +0000 (22:22 +0100)
- 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.

src/Util.cpp
src/ccache.cpp
src/legacy_util.cpp
src/stats.cpp

index abca1d34f56fbfdf30a33ca428787084aa8fb89d..dff944d84c09410370d4c929403e4cbf138b98b1 100644 (file)
@@ -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) {
index a1fa6a42d6c7f00c08a1cf91378e8990580c0b7d..9f44a65577b555dc8d9e7fbf4ab0342cd507da0e 100644 (file)
@@ -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);
 
index e003bbf69d10003c1f27c4df084432611d6bbd24..ef46e5415fdfa23e5f1dceba99c860c0ed9de537 100644 (file)
@@ -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)) {
index df093d708ec440ce1fecfb28c15c464f11dbc642..ebfccbedac3b7716dfb569363052c9215511cbf2 100644 (file)
@@ -426,7 +426,7 @@ stats_flush_to_file(const Config& config,
 void
 stats_flush(void* context)
 {
-  Context& ctx = *static_cast<Context*>(context);
+  const Context& ctx = *static_cast<Context*>(context);
   stats_flush_to_file(ctx.config, ctx.stats_file, ctx.counter_updates);
 }