emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Warning in svg_load_image


From: Michael Welsh Duggan
Subject: Re: Warning in svg_load_image
Date: Wed, 23 Feb 2022 12:11:24 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)

Eli Zaretskii <eliz@gnu.org> writes:

>        "xmlns:xi=\"http://www.w3.org/2001/XInclude\"; "
>        "style=\"color: #%06X; fill: currentColor;\" "
>        "width=\"%d\" height=\"%d\" preserveAspectRatio=\"none\" "
> -      "viewBox=\"0 0 %f %f\">"
> +      "viewBox=\"0 0 %5.0f %5.0f\">"
>        "<rect width=\"100%%\" height=\"100%%\" fill=\"#%06X\"/>"
>        "<xi:include href=\"data:image/svg+xml;base64,%s\"></xi:include>"
>        "</svg>";
> @@ -10801,7 +10801,9 @@ svg_load_image (struct frame *f, struct image *img, 
> char *contents,
>  
>      if (buffer_size <= snprintf (wrapped_contents, buffer_size, wrapper,
>                                foreground & 0xFFFFFF, width, height,
> -                              viewbox_width, viewbox_height,
> +                              /* Sanitize the viewBox dimensions.  */
> +                              min (viewbox_width, 10000.),
> +                              min (viewbox_height, 10000.),
>                                background & 0xFFFFFF,
>                                SSDATA (encoded_contents)))
>        goto rsvg_error;
>

So, a couple of questions and comments...  

As mentioned in other messages, % sizes affect only the minimum sizes of
results, so changing those values shouldn't help.  (It's possible that
using * might, but only as a possible subversion of the heuristics that
this warning uses.)

The principled way to solve this would be to call the snprintf twice,
the first time with a zero-sized buffer, and then to use the return
value to allocate the actual buffer.  This is a pessimisation, but I
don't know if it's a bad one (it depends on how frequently this code
would be called.

Po Lu, what architecture are you compiling for?  As I haven't been able
to trigger this in my own builds, I am guessing that the fact that you
are is due to differences in how the compiler is interpreting the
possible range of values for %f and maybe for %d.  What are sizeof(int)
and sizeof(float) on this architecture?

-- 
Michael Welsh Duggan
(md5i@md5i.com)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]