Throw exception if width or height - padding * 2 is 0 or less.
the build was successful Details

This commit is contained in:
tastytea 2018-12-27 23:18:06 +01:00
parent 0425ee3fec
commit 35a1cc2233
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
1 changed files with 10 additions and 4 deletions

View File

@ -45,12 +45,18 @@ Magick::Image Identiconpp::generate(const string &digest, const uint16_t width)
{
ttdebug << "Using digest: " << digest << '\n';
check_entropy(digest, _type);
const uint16_t imgwidth = width - _padding[0] * 2;
const uint16_t imgheight =
const std::int16_t imgwidth = width - _padding[0] * 2;
const std::int16_t imgheight =
std::round(static_cast<float>(imgwidth) / _columns * _rows);
ttdebug << "width: " << std::to_string(imgwidth + _padding[0] * 2)
<< ", height: " << std::to_string(imgheight + _padding[1] * 2)
ttdebug << "width: " << std::to_string(imgwidth)
<< "+" << std::to_string(_padding[0] * 2)
<< ", height: " << std::to_string(imgheight)
<< "+" << std::to_string(_padding[1] * 2)
<< "\n";
if (imgwidth <= 0 || imgheight <= 0)
{
throw std::invalid_argument("Width or height is zero or less.");
}
Magick::Image img;
switch (_type)