C-interface: Added more error checking.

This commit is contained in:
tastytea 2019-01-04 19:10:01 +01:00
parent cef436faf5
commit 28d08342d3
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
2 changed files with 15 additions and 9 deletions

View File

@ -76,13 +76,19 @@ bool identiconpp_setup(const uint8_t columns, const uint8_t rows,
uint64_t identiconpp_generate(const char magick[], uint64_t identiconpp_generate(const char magick[],
const char digest[], const uint16_t width) const char digest[], const uint16_t width)
{ {
Magick::Image img = identicon->generate(digest, width); try
Magick::Blob blob; {
img.magick(magick); Magick::Image img = identicon->generate(digest, width);
img.write(&blob); Magick::Blob blob;
base64 = blob.base64(); img.magick(magick);
img.write(&blob);
return blob.base64().length(); base64 = blob.base64();
return blob.base64().length();
}
catch (const std::exception &e)
{
return 0;
}
} }
const char *identiconpp_base64() const char *identiconpp_base64()

View File

@ -55,7 +55,7 @@ extern "C"
* @param foreground_len Length of the array of foreground colors * @param foreground_len Length of the array of foreground colors
* @param padding Padding in pixels { left & right, top & down } * @param padding Padding in pixels { left & right, top & down }
* *
* @return { description_of_the_return_value } * @return false on error.
*/ */
bool identiconpp_setup(const uint8_t columns, const uint8_t rows, bool identiconpp_setup(const uint8_t columns, const uint8_t rows,
identiconpp_algorithm type, identiconpp_algorithm type,
@ -71,7 +71,7 @@ extern "C"
* @param digest The pre-computed digest * @param digest The pre-computed digest
* @param width The width of the identicon * @param width The width of the identicon
* *
* @return Length of the generated base64-string * @return Length of the generated base64-string, or 0 on error.
*/ */
uint64_t identiconpp_generate(const char magick[], uint64_t identiconpp_generate(const char magick[],
const char digest[], const uint16_t width); const char digest[], const uint16_t width);