Skip to content

Commit

Permalink
Added: ifstream check and try-catch for stod() in Tools::system_uptime()
Browse files Browse the repository at this point in the history
  • Loading branch information
aristocratos committed Sep 25, 2021
1 parent 5ae05f0 commit 528df4d
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/linux/btop_collect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1611,8 +1611,15 @@ namespace Tools {
double system_uptime() {
string upstr;
ifstream pread(Shared::procPath / "uptime");
getline(pread, upstr, ' ');
pread.close();
return stod(upstr);
if (pread.good()) {
try {
getline(pread, upstr, ' ');
pread.close();
return stod(upstr);
}
catch (const std::invalid_argument&) {}
catch (const std::out_of_range&) {}
}
throw std::runtime_error("Failed get uptime from from " + (string)Shared::procPath + "/uptime");
}
}

0 comments on commit 528df4d

Please sign in to comment.