]> git.eshelyaron.com Git - emacs.git/commitdiff
Prefer snprintf to sprintf in image.c
authorStefan Kangas <stefankangas@gmail.com>
Tue, 21 Jan 2025 23:47:02 +0000 (00:47 +0100)
committerEshel Yaron <me@eshelyaron.com>
Thu, 23 Jan 2025 10:25:01 +0000 (11:25 +0100)
* src/image.c (image_background, image_build_heuristic_mask)
(png_load_body): Prefer snprintf to sprintf.

(cherry picked from commit cdcfffd50a61058b135ddca1f748a5a20a7da32e)

src/image.c

index 7ab6289bb2a6efb0c73965c1403c3168a35c3878..2b898e1280512dbda94c41da1673c0fc4d10fd10 100644 (file)
@@ -1995,10 +1995,10 @@ image_background (struct image *img, struct frame *f, Emacs_Pix_Context pimg)
 #ifdef USE_CAIRO
       {
        char color_name[30];
-       sprintf (color_name, "#%04x%04x%04x",
-                (unsigned int) RED16_FROM_ULONG (bg),
-                (unsigned int) GREEN16_FROM_ULONG (bg),
-                (unsigned int) BLUE16_FROM_ULONG (bg));
+       snprintf (color_name, sizeof color_name, "#%04x%04x%04x",
+                 (unsigned int) RED16_FROM_ULONG (bg),
+                 (unsigned int) GREEN16_FROM_ULONG (bg),
+                 (unsigned int) BLUE16_FROM_ULONG (bg));
        bg = image_alloc_image_color (f, img, build_string (color_name), 0);
       }
 #endif
@@ -7386,8 +7386,8 @@ image_build_heuristic_mask (struct frame *f, struct image *img,
        {
 #ifndef USE_CAIRO
          char color_name[30];
-         sprintf (color_name, "#%04x%04x%04x",
-                  rgb[0] + 0u, rgb[1] + 0u, rgb[2] + 0u);
+         snprintf (color_name, sizeof color_name, "#%04x%04x%04x",
+                   rgb[0] + 0u, rgb[1] + 0u, rgb[2] + 0u);
          bg = (
 #ifdef HAVE_NTGUI
                0x00ffffff & /* Filter out palette info.  */
@@ -8537,7 +8537,8 @@ png_load_body (struct frame *f, struct image *img, struct png_load_context *c)
          img->background = lookup_rgb_color (f, bg->red, bg->green, bg->blue);
 #else  /* USE_CAIRO */
          char color_name[30];
-         sprintf (color_name, "#%04x%04x%04x", bg->red, bg->green, bg->blue);
+         snprintf (color_name, sizeof color_name, "#%04x%04x%04x",
+                   bg->red, bg->green, bg->blue);
          img->background
            = image_alloc_image_color (f, img, build_string (color_name), 0);
 #endif /* USE_CAIRO */