Merge pull request #1304 from mamins1376/fix-1303

Fix divide by zero (#1303)
pull/1311/head
Alex 2021-10-29 13:22:01 +02:00 committed by GitHub
commit 8498ddefca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 4 deletions

View File

@ -67,9 +67,11 @@ std::string ALabel::getIcon(uint16_t percentage, const std::string& alt, uint16_
} }
if (format_icons.isArray()) { if (format_icons.isArray()) {
auto size = format_icons.size(); auto size = format_icons.size();
if (size) {
auto idx = std::clamp(percentage / ((max == 0 ? 100 : max) / size), 0U, size - 1); auto idx = std::clamp(percentage / ((max == 0 ? 100 : max) / size), 0U, size - 1);
format_icons = format_icons[idx]; format_icons = format_icons[idx];
} }
}
if (format_icons.isString()) { if (format_icons.isString()) {
return format_icons.asString(); return format_icons.asString();
} }
@ -90,9 +92,11 @@ std::string ALabel::getIcon(uint16_t percentage, const std::vector<std::string>&
} }
if (format_icons.isArray()) { if (format_icons.isArray()) {
auto size = format_icons.size(); auto size = format_icons.size();
if (size) {
auto idx = std::clamp(percentage / ((max == 0 ? 100 : max) / size), 0U, size - 1); auto idx = std::clamp(percentage / ((max == 0 ? 100 : max) / size), 0U, size - 1);
format_icons = format_icons[idx]; format_icons = format_icons[idx];
} }
}
if (format_icons.isString()) { if (format_icons.isString()) {
return format_icons.asString(); return format_icons.asString();
} }