From 4e7b1aa7aed4779313abea07b042afea4cedfe53 Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Wed, 22 Jan 2025 00:47:02 +0100 Subject: [PATCH] Prefer snprintf to sprintf in image.c * src/image.c (image_background, image_build_heuristic_mask) (png_load_body): Prefer snprintf to sprintf. (cherry picked from commit cdcfffd50a61058b135ddca1f748a5a20a7da32e) --- src/image.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/image.c b/src/image.c index 7ab6289bb2a..2b898e12805 100644 --- a/src/image.c +++ b/src/image.c @@ -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 */ -- 2.39.5