Make sure we don't crash on empty lists and we don't divide by zero

master
Tomasz Golinski 2021-01-03 04:51:54 +01:00
rodzic be8e2b783e
commit 490714ec43
2 zmienionych plików z 9 dodań i 1 usunięć

Wyświetl plik

@ -51,6 +51,8 @@ static std::string string_mangle(const std::string& str) {
}
void show_histogram(const pCaches& cc, std::string Cache::*ptr, const std::string& caption, bool html, bool sort_by_val) {
if (cc.empty()) return;
std::map<std::string, int> histogram;
for (auto el : cc)
@ -60,6 +62,8 @@ void show_histogram(const pCaches& cc, std::string Cache::*ptr, const std::strin
}
void show_histogram(const Caches& cc, std::string Cache::*ptr, const std::string& caption, bool html, bool sort_by_val) {
if (cc.empty()) return;
std::map<std::string, int> histogram;
for (auto el : cc)
@ -69,6 +73,8 @@ void show_histogram(const Caches& cc, std::string Cache::*ptr, const std::string
}
void show_histogram(const std::map<std::string, int>& data, const std::string& caption, bool html, bool sort_by_val) {
if (data.empty()) return;
int HIST_MAX = 20;
std::vector<std::pair<std::string, int>> pairs;
@ -118,6 +124,8 @@ void show_histogram(const std::map<std::string, int>& data, const std::string& c
}
void show_nested_histogram(const pCaches& fcc, std::string Cache::*ptr, std::string Cache::*ptr2, const std::string& caption, bool html, bool sort_by_val) {
if (fcc.empty()) return;
std::map<std::string, int> histogram;
std::vector<std::pair<std::string, int>> pairs;

Wyświetl plik

@ -828,7 +828,7 @@ int main(int argc, char** argv) {
for (auto el : fcc)
region_found_count[el->region]++;
for (auto& i : region_count)
i.second = region_found_count[i.first] * 100 / i.second;
if (i.second != 0) i.second = region_found_count[i.first] * 100 / i.second;
show_histogram(region_count, "Percentage", 1);
}