From: Eli Zaretskii Date: Tue, 13 Sep 2022 14:12:40 +0000 (+0300) Subject: ; * src/image.c (svg_load_image): Another minor cleanup. (Bug#51104) X-Git-Tag: emacs-29.0.90~1856^2~556 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=48c562fb748623ed01385eaf215333a6c2edac80;p=emacs.git ; * src/image.c (svg_load_image): Another minor cleanup. (Bug#51104) --- diff --git a/src/image.c b/src/image.c index 52fdf861384..551da716434 100644 --- a/src/image.c +++ b/src/image.c @@ -11183,6 +11183,10 @@ svg_load_image (struct frame *f, struct image *img, char *contents, char *wrapped_contents = NULL; ptrdiff_t wrapped_size; + bool empty_errmsg = true; + const char *errmsg = ""; + ptrdiff_t errlen = 0; + #if LIBRSVG_CHECK_VERSION (2, 48, 0) char *css = NULL; #endif @@ -11540,20 +11544,22 @@ svg_load_image (struct frame *f, struct image *img, char *contents, return true; rsvg_error: - if (!err || !err->message[0]) - image_error ("Error parsing SVG image"); - else + if (err && err->message[0]) { - char *errmsg = err->message; - ptrdiff_t errlen = strlen (errmsg); - + errmsg = err->message; + errlen = strlen (errmsg); /* Remove trailing whitespace from the error message text. It has a newline at the end, and perhaps more whitespace. */ - while (c_isspace (errmsg[errlen - 1])) + while (errlen && c_isspace (errmsg[errlen - 1])) errlen--; - image_error ("Error parsing SVG image: %s", make_string (errmsg, errlen)); + empty_errmsg = errlen == 0; } + if (empty_errmsg) + image_error ("Error parsing SVG image"); + else + image_error ("Error parsing SVG image: %s", make_string (errmsg, errlen)); + if (err) g_error_free (err);