added checks to mitigate floating point crashes

This commit is contained in:
fourtf
2020-04-19 21:05:40 +02:00
parent 6b512d1052
commit 6052846bc3
12 changed files with 74 additions and 40 deletions
+4 -1
View File
@@ -53,7 +53,10 @@ static float relativeSimilarity(const QString &str1, const QString &str2)
}
}
return z == 0 ? 0.f : float(z) / std::max(str1.size(), str2.size());
// ensure that no div by 0
return z == 0 ? 0.f
: float(z) /
std::max<int>(1, std::max(str1.size(), str2.size()));
};
float IrcMessageHandler::similarity(
@@ -60,6 +60,7 @@ QColor getRandomColor(const QVariant &userId)
colorSeed = std::rand();
}
assert(twitchUsernameColors.size() != 0);
const auto colorIndex = colorSeed % twitchUsernameColors.size();
return twitchUsernameColors[colorIndex];
}