Skip to content

Commit

Permalink
Avoid potential uninitialzed variables
Browse files Browse the repository at this point in the history
Reported-by clang:

    src/linux/btop_collect.cpp:489:10: error: variable 'high' may be uninitialized when used here [-Werror,-Wconditional-uninitialized]
      489 |                                         if (high < 1) high = 80;
          |                                             ^~~~
    src/linux/btop_collect.cpp:482:18: note: initialize the variable 'high' to silence this warning
      482 |                                         int64_t high, crit;
          |                                                     ^
          |                                                      = 0
    src/linux/btop_collect.cpp:490:10: error: variable 'crit' may be uninitialized when used here [-Werror,-Wconditional-uninitialized]
      490 |                                         if (crit < 1) crit = 95;
          |                                             ^~~~
    src/linux/btop_collect.cpp:482:24: note: initialize the variable 'crit' to silence this warning
      482 |                                         int64_t high, crit;
          |                                                           ^
          |                                                            = 0
    src/linux/btop_collect.cpp:1648:29: error: variable 'totalMem' may be uninitialized when used here [-Werror,-Wconditional-uninitialized]
     1648 |                 if (not meminfo.good() or totalMem == 0)
          |                                           ^~~~~~~~
    src/linux/btop_collect.cpp:1642:19: note: initialize the variable 'totalMem' to silence this warning
     1642 |                 int64_t totalMem;
          |                                 ^
          |                                  = 0
  • Loading branch information
bad code committed Sep 22, 2024
1 parent cfad636 commit d4f5919
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/linux/btop_collect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ namespace Cpu {
const string sensor_name = "thermal" + to_string(i) + "/" + label;
const int64_t temp = stol(readfile(basepath / "temp", "0")) / 1000;

int64_t high, crit;
int64_t high = 0, crit = 0;
for (int ii = 0; fs::exists(basepath / string("trip_point_" + to_string(ii) + "_temp")); ii++) {
const string trip_type = readfile(basepath / string("trip_point_" + to_string(ii) + "_type"));
if (not is_in(trip_type, "high", "critical")) continue;
Expand Down Expand Up @@ -1786,7 +1786,7 @@ namespace Mem {

uint64_t get_totalMem() {
ifstream meminfo(Shared::procPath / "meminfo");
int64_t totalMem;
int64_t totalMem = 0;
if (meminfo.good()) {
meminfo.ignore(SSmax, ':');
meminfo >> totalMem;
Expand Down

0 comments on commit d4f5919

Please sign in to comment.