]> git.eshelyaron.com Git - emacs.git/commitdiff
When debugging image.c, abort if silent truncation
authorPaul Eggert <eggert@cs.ucla.edu>
Wed, 22 Jan 2025 06:16:22 +0000 (22:16 -0800)
committerEshel Yaron <me@eshelyaron.com>
Thu, 23 Jan 2025 10:25:06 +0000 (11:25 +0100)
* src/image.c (image_build_heuristic_mask, png_load_body):
Abort if snprintf truncated.  (If truncation is not possible
here we should use sprintf instead, as that simplifies
automatic runtime checking.)

(cherry picked from commit 8ff7338fdd05fe6d21765711327a99c87cfd7613)

src/image.c

index 2b898e1280512dbda94c41da1673c0fc4d10fd10..1db2df736a5ef81596b6993febc46a3fa5ea8eca 100644 (file)
@@ -7386,8 +7386,9 @@ image_build_heuristic_mask (struct frame *f, struct image *img,
        {
 #ifndef USE_CAIRO
          char color_name[30];
-         snprintf (color_name, sizeof color_name, "#%04x%04x%04x",
-                   rgb[0] + 0u, rgb[1] + 0u, rgb[2] + 0u);
+         int len = snprintf (color_name, sizeof color_name, "#%04x%04x%04x",
+                             rgb[0] + 0u, rgb[1] + 0u, rgb[2] + 0u);
+         eassert (len < sizeof color_name);
          bg = (
 #ifdef HAVE_NTGUI
                0x00ffffff & /* Filter out palette info.  */
@@ -8537,8 +8538,9 @@ 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];
-         snprintf (color_name, sizeof color_name, "#%04x%04x%04x",
-                   bg->red, bg->green, bg->blue);
+         int len = snprintf (color_name, sizeof color_name, "#%04x%04x%04x",
+                             bg->red, bg->green, bg->blue);
+         eassert (len < sizeof color_name);
          img->background
            = image_alloc_image_color (f, img, build_string (color_name), 0);
 #endif /* USE_CAIRO */