diff --git a/examples/gif2webp.c b/examples/gif2webp.c index 6cd8b3c4..5f4d275c 100644 --- a/examples/gif2webp.c +++ b/examples/gif2webp.c @@ -132,23 +132,24 @@ static int GetColorFromIndex(const ColorMapObject* const color_map, GifWord idx, } } -static void DisplayGifError(const GifFileType* const gif) { +static void DisplayGifError(const GifFileType* const gif, int gif_error) { // GIFLIB_MAJOR is only defined in libgif >= 4.2.0. // libgif 4.2.0 has retired PrintGifError() and added GifErrorString(). #if defined(GIFLIB_MAJOR) && defined(GIFLIB_MINOR) && \ ((GIFLIB_MAJOR == 4 && GIFLIB_MINOR >= 2) || GIFLIB_MAJOR > 4) #if GIFLIB_MAJOR >= 5 // Static string actually, hence the const char* cast. - const char* error_str = (const char*)GifErrorString(gif->Error); + const char* error_str = (const char*)GifErrorString( + (gif == NULL) ? gif_error : gif->Error); #else const char* error_str = (const char*)GifErrorString(); (void)gif; #endif if (error_str == NULL) error_str = "Unknown error"; - fprintf(stderr, "GIFLib Error: %s\n", error_str); + fprintf(stderr, "GIFLib Error %d: %s\n", gif_error, error_str); #else (void)gif; - fprintf(stderr, "GIFLib Error: "); + fprintf(stderr, "GIFLib Error %d: ", gif_error); PrintGifError(); fprintf(stderr, "\n"); #endif @@ -186,7 +187,7 @@ static void Help(void) { int main(int argc, const char *argv[]) { int verbose = 0; - int gif_error = -1; + int gif_error = GIF_ERROR; WebPMuxError err = WEBP_MUX_OK; int ok = 0; const char *in_file = NULL, *out_file = NULL; @@ -458,7 +459,7 @@ int main(int argc, const char *argv[]) { // All OK. ok = 1; - gif_error = 0; + gif_error = GIF_OK; End: WebPDataClear(&webp_data); @@ -466,8 +467,8 @@ int main(int argc, const char *argv[]) { WebPPictureFree(&picture); if (out != NULL && out_file != NULL) fclose(out); - if (gif_error != 0) { - DisplayGifError(gif); + if (gif_error != GIF_OK) { + DisplayGifError(gif, gif_error); } if (gif != NULL) { DGifCloseFile(gif);