From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.devel Subject: Re: Warning in svg_load_image Date: Mon, 21 Feb 2022 15:26:07 +0200 Message-ID: <83r17wuz9s.fsf@gnu.org> References: <87ilt8hcz4.fsf.ref@yahoo.com> <87ilt8hcz4.fsf@yahoo.com> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="3790"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Po Lu Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon Feb 21 14:57:18 2022 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nM9Bk-0000jc-WD for ged-emacs-devel@m.gmane-mx.org; Mon, 21 Feb 2022 14:57:17 +0100 Original-Received: from localhost ([::1]:54108 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nM9Bj-0006LD-Qm for ged-emacs-devel@m.gmane-mx.org; Mon, 21 Feb 2022 08:57:15 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:38918) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nM8hX-00031g-AL for emacs-devel@gnu.org; Mon, 21 Feb 2022 08:26:03 -0500 Original-Received: from [2001:470:142:3::e] (port=51360 helo=fencepost.gnu.org) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nM8hW-0006xl-Ul; Mon, 21 Feb 2022 08:26:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=Y69e8tdnpiannWwYnPVNpEtT1g3uu+ZuYrCIyFNh8fQ=; b=nc4DAUY0+n/3 QQyJSqB/PKNkiBwSjE0mioGbOvc1yJya42hfzJmHExY5d8R+0OouDVb329bwTZfSinac1zjw9jsLv S1fGiW/g1BXW82FHN0iEIHoob1etcuSSVx35LlGDx4FTVS18bPiFJr9V3Ne2fvZm2poeRg6eqzY9p 5TVSGNOH/l+0MxU9GRyZGBn/QV7t8uXPAHRm+vhnOYeV2pN9LPc4XdQeqf1W4jkWt12biEbae0Xzt LH35gp/vRv7g5bQJ3E87m+vMNwwOkPKcv1upqu98QxwAEDpSP3V8kvfTzmGEflwfkoAyzEffjL1PS 5pUtHokfQP9K51C+QYd62Q==; Original-Received: from [87.69.77.57] (port=3269 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nM8hW-0000HV-Dd; Mon, 21 Feb 2022 08:26:02 -0500 In-Reply-To: <87ilt8hcz4.fsf@yahoo.com> (message from Po Lu on Mon, 21 Feb 2022 15:53:51 +0800) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:286561 Archived-At: > From: Po Lu > Date: Mon, 21 Feb 2022 15:53:51 +0800 > > image.c: In function 'svg_load_image': > image.c:10776:7: warning: '%f' directive output may be truncated writing between 8 and 317 bytes into a region of size between 167 and 187 [-Wformat-truncation=] > " ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > image.c:10780:22: note: format string is defined here > "viewBox=\"0 0 %f %f\">" > ^~ > image.c:10776:7: note: directive argument in the range [0, 16777215] > " ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > image.c:10776:7: note: assuming directive output of 1 byte > image.c:10802:24: note: 'snprintf' output 330 or more bytes (assuming 331) into a destination of size 383 > if (buffer_size <= snprintf (wrapped_contents, buffer_size, wrapper, > ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > foreground & 0xFFFFFF, width, height, > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > viewbox_width, viewbox_height, > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > background & 0xFFFFFF, > ~~~~~~~~~~~~~~~~~~~~~~ > SSDATA (encoded_contents))) > ~~~~~~~~~~~~~~~~~~~~~~~~~~ > > Does anyone want to fix this? Not really, but does the below fix these, by chance? diff --git a/src/image.c b/src/image.c index e2ba744..02b58b9 100644 --- a/src/image.c +++ b/src/image.c @@ -10632,9 +10632,9 @@ svg_load_image (struct frame *f, struct image *img, char *contents, strncpy (css, SSDATA (lcss), SBYTES (lcss)); *(css + SBYTES (lcss) + 1) = 0; } -#endif +#endif /* LIBRSVG >= 2.48.0 */ -#else +#else /* LIBRSVG < 2.32.0 */ /* Make a handle to a new rsvg object. */ rsvg_handle = rsvg_handle_new (); eassume (rsvg_handle); @@ -10657,7 +10657,7 @@ svg_load_image (struct frame *f, struct image *img, char *contents, it for further writes. */ rsvg_handle_close (rsvg_handle, &err); if (err) goto rsvg_error; -#endif +#endif /* LIBRSVG 2.32.0 */ /* Get the image dimensions. */ #if LIBRSVG_CHECK_VERSION (2, 46, 0) @@ -10727,13 +10727,13 @@ svg_load_image (struct frame *f, struct image *img, char *contents, viewbox_height = viewbox.y + viewbox.height; } } -#else +#else /* LIBRSVG < 2.46.0 */ /* In librsvg before 2.46.0, guess the viewbox from the image dimensions. */ RsvgDimensionData dimension_data; rsvg_handle_get_dimensions (rsvg_handle, &dimension_data); viewbox_width = dimension_data.width; viewbox_height = dimension_data.height; -#endif +#endif /* LIBRSVG < 2.46.0 */ #ifdef HAVE_NATIVE_TRANSFORMS compute_image_size (viewbox_width, viewbox_height, img, @@ -10777,7 +10777,7 @@ svg_load_image (struct frame *f, struct image *img, char *contents, "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 %.0f %.0f\">" "" "" ""; @@ -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;