added checks to mitigate floating point crashes
This commit is contained in:
@@ -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];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user