From 3b24ac538858d994a74826361a1af3f802dd065a Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Fri, 16 Aug 2024 17:19:12 -0700 Subject: [PATCH 4/6] =?UTF-8?q?Don=E2=80=99t=20ignore=20-Wclobbered=20in?= =?UTF-8?q?=20image.c?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fix is also prompted by Emacs bug#71744. * src/image.c: Do not ignore -Wclobbered. (png_load_body): Fix violations of the C standard, where setjmp clobbered c. Move mask_img decl to pacify GCC. (jpeg_load_body): Don’t make fp volatile; solve that problem in a better way, via a new fp_volatile local. Fix violations of the C standard, where setjmp clobbered mgr, img, and ximg. If __GNUC__ && !__clang__, add useless assignments to pacify GCC. --- src/image.c | 44 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/src/image.c b/src/image.c index 3965a6ce6f8..48694a13341 100644 --- a/src/image.c +++ b/src/image.c @@ -63,11 +63,6 @@ Copyright (C) 1989-2024 Free Software Foundation, Inc. #include TERM_HEADER #endif /* HAVE_WINDOW_SYSTEM */ -/* Work around GCC bug 54561. */ -#if GNUC_PREREQ (4, 3, 0) -# pragma GCC diagnostic ignored "-Wclobbered" -#endif - #ifdef HAVE_X_WINDOWS typedef struct x_bitmap_record Bitmap_Record; #ifndef USE_CAIRO @@ -8188,7 +8183,7 @@ png_load_body (struct frame *f, struct image *img, struct png_load_context *c) bool transparent_p; struct png_memory_storage tbr; /* Data to be read */ ptrdiff_t nbytes; - Emacs_Pix_Container ximg, mask_img = NULL; + Emacs_Pix_Container ximg; /* Find out what file to load. */ specified_file = image_spec_value (img->spec, QCfile, NULL); @@ -8279,9 +8274,12 @@ png_load_body (struct frame *f, struct image *img, struct png_load_context *c) /* Set error jump-back. We come back here when the PNG library detects an error. */ + + struct png_load_context *volatile c_volatile = c; if (FAST_SETJMP (PNG_JMPBUF (png_ptr))) { error: + c = c_volatile; if (c->png_ptr) png_destroy_read_struct (&c->png_ptr, &c->info_ptr, &c->end_info); xfree (c->pixels); @@ -8291,6 +8289,13 @@ png_load_body (struct frame *f, struct image *img, struct png_load_context *c) return 0; } +#if GCC_LINT && __GNUC__ && !__clang__ + /* These useless assignments pacify GCC 14.2.1 x86-64 + . */ + c = c_volatile; + fp = c->fp; +#endif + /* Read image info. */ if (!NILP (specified_data)) png_set_read_fn (png_ptr, &tbr, png_read_from_memory); @@ -8417,6 +8422,7 @@ png_load_body (struct frame *f, struct image *img, struct png_load_context *c) /* Create an image and pixmap serving as mask if the PNG image contains an alpha channel. */ + Emacs_Pix_Container mask_img = NULL; if (channels == 4 && transparent_p && !image_create_x_image_and_pixmap (f, img, width, height, 1, @@ -8912,13 +8918,13 @@ jpeg_load_body (struct frame *f, struct image *img, struct my_jpeg_error_mgr *mgr) { Lisp_Object specified_file, specified_data; - FILE *volatile fp = NULL; + FILE *fp = NULL; JSAMPARRAY buffer; int row_stride, x, y; int width, height; int i, ir, ig, ib; unsigned long *colors; - Emacs_Pix_Container ximg = NULL; + Emacs_Pix_Container volatile ximg_volatile = NULL; /* Open the JPEG file. */ specified_file = image_spec_value (img->spec, QCfile, NULL); @@ -8953,8 +8959,15 @@ jpeg_load_body (struct frame *f, struct image *img, error is detected. This function will perform a longjmp. */ mgr->cinfo.err = jpeg_std_error (&mgr->pub); mgr->pub.error_exit = my_error_exit; + struct my_jpeg_error_mgr *volatile mgr_volatile = mgr; + struct image *volatile img_volatile = img; + FILE *volatile fp_volatile = fp; if (sys_setjmp (mgr->setjmp_buffer)) { + mgr = mgr_volatile; + img = img_volatile; + fp = fp_volatile; + switch (mgr->failure_code) { case MY_JPEG_ERROR_EXIT: @@ -8980,6 +8993,7 @@ jpeg_load_body (struct frame *f, struct image *img, jpeg_destroy_decompress (&mgr->cinfo); /* If we already have an XImage, free that. */ + Emacs_Pix_Container ximg = ximg_volatile; if (ximg) image_destroy_x_image (ximg); /* Free pixmap and colors. */ @@ -8987,6 +9001,14 @@ jpeg_load_body (struct frame *f, struct image *img, return 0; } +#if GCC_LINT && __GNUC__ && !__clang__ + /* These useless assignments pacify GCC 14.2.1 x86-64 + . */ + mgr = mgr_volatile; + img = img_volatile; + fp = fp_volatile; +#endif + /* Create the JPEG decompression object. Let it read from fp. Read the JPEG image header. */ jpeg_CreateDecompress (&mgr->cinfo, JPEG_LIB_VERSION, sizeof *&mgr->cinfo); @@ -9013,7 +9035,11 @@ jpeg_load_body (struct frame *f, struct image *img, } /* Create X image and pixmap. */ - if (!image_create_x_image_and_pixmap (f, img, width, height, 0, &ximg, 0)) + Emacs_Pix_Container ximg; + bool ximg_ok = image_create_x_image_and_pixmap (f, img, width, height, 0, + &ximg, 0); + ximg_volatile = ximg; + if (!ximg_ok) { mgr->failure_code = MY_JPEG_CANNOT_CREATE_X; sys_longjmp (mgr->setjmp_buffer, 1); -- 2.43.0