SDL_image: IMG_SavePNG_RW_libpng: add volatile to locals color_ptr and source,

From 5dc391d750e63711f2ebd6f44bd193e6845fd06f Mon Sep 17 00:00:00 2001
From: Ozkan Sezer <[EMAIL REDACTED]>
Date: Fri, 26 Jan 2024 11:11:04 +0300
Subject: [PATCH] IMG_SavePNG_RW_libpng: add volatile to locals color_ptr and
 source,

and move initialization of png_color_type

Silences -Wclobbered warnings from gcc:

/tmp/SDL_image/src/IMG_png.c: In function 'IMG_SavePNG_RW_libpng':
/tmp/SDL_image/src/IMG_png.c:580:16: warning: variable 'color_ptr' might be clobbered by 'longjmp' or 'vfork' [-Wclobbered]
     png_colorp color_ptr = NULL;
                ^
/tmp/SDL_image/src/IMG_png.c:584:9: warning: variable 'png_color_type' might be clobbered by 'longjmp' or 'vfork' [-Wclobbered]
     int png_color_type = PNG_COLOR_TYPE_RGB_ALPHA;
         ^
Reference issue: https://github.com/libsdl-org/SDL_image/issues/416
---
 src/IMG_png.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/IMG_png.c b/src/IMG_png.c
index 95b51462..640cc5b0 100644
--- a/src/IMG_png.c
+++ b/src/IMG_png.c
@@ -577,11 +577,11 @@ static int IMG_SavePNG_RW_libpng(SDL_Surface *surface, SDL_RWops *dst)
 {
     png_structp png_ptr;
     png_infop info_ptr;
-    png_colorp color_ptr = NULL;
+    png_colorp volatile color_ptr = NULL;
     Uint8 transparent_table[256];
-    SDL_Surface *source = surface;
+    SDL_Surface * volatile source = surface;
     SDL_Palette *palette;
-    int png_color_type = PNG_COLOR_TYPE_RGB_ALPHA;
+    int png_color_type;
 
     if (!IMG_Init(IMG_INIT_PNG)) {
         return -1;
@@ -652,6 +652,7 @@ static int IMG_SavePNG_RW_libpng(SDL_Surface *surface, SDL_RWops *dst)
     else if (surface->format->format != png_format) {
         /* Otherwise, (surface has alpha data), and it is not in the exact right
            format , so it should be converted to that */
+        png_color_type = PNG_COLOR_TYPE_RGB_ALPHA;
         source = SDL_ConvertSurfaceFormat(surface, png_format);
     }