SDL: Fixed warnings building with Visual Studio (379ae)

From 379aea5c2dfda007ca79c404ef04de3545e0e415 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Thu, 5 Sep 2024 20:09:48 -0700
Subject: [PATCH] Fixed warnings building with Visual Studio

---
 src/render/sdlgpu/SDL_render_gpu.c            | 28 ++++++++++++++-----
 src/render/sdlgpu/SDL_shaders_gpu.c           |  2 +-
 .../sdlgpu/shaders/color.frag.sm50.dxbc.h     |  4 +--
 .../sdlgpu/shaders/linepoint.vert.sm50.dxbc.h |  4 +--
 .../shaders/texture_rgb.frag.sm50.dxbc.h      |  4 +--
 .../shaders/texture_rgba.frag.sm50.dxbc.h     |  4 +--
 .../sdlgpu/shaders/tri_color.vert.sm50.dxbc.h |  4 +--
 .../shaders/tri_texture.vert.sm50.dxbc.h      |  4 +--
 8 files changed, 34 insertions(+), 20 deletions(-)

diff --git a/src/render/sdlgpu/SDL_render_gpu.c b/src/render/sdlgpu/SDL_render_gpu.c
index 391b65600f812..c5403a095d52e 100644
--- a/src/render/sdlgpu/SDL_render_gpu.c
+++ b/src/render/sdlgpu/SDL_render_gpu.c
@@ -613,7 +613,7 @@ static bool InitVertexBuffer(GPU_RenderData *data, Uint32 size)
     data->vertices.buffer = SDL_CreateGPUBuffer(data->device, &bci);
 
     if (!data->vertices.buffer) {
-        return -1;
+        return false;
     }
 
     SDL_GPUTransferBufferCreateInfo tbci;
@@ -622,7 +622,12 @@ static bool InitVertexBuffer(GPU_RenderData *data, Uint32 size)
     tbci.usage = SDL_GPU_TRANSFERBUFFERUSAGE_UPLOAD;
 
     data->vertices.transfer_buf = SDL_CreateGPUTransferBuffer(data->device, &tbci);
-    return (bool)data->vertices.transfer_buf;
+
+    if (!data->vertices.transfer_buf) {
+        return false;
+    }
+
+    return true;
 }
 
 static bool UploadVertices(GPU_RenderData *data, void *vertices, size_t vertsize)
@@ -852,8 +857,13 @@ static SDL_Surface *GPU_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect
     }
 
     Uint32 bpp = SDL_BYTESPERPIXEL(pixfmt);
-    Uint32 row_size = rect->w * bpp;
-    Uint32 image_size = row_size * rect->h;
+    size_t row_size, image_size;
+
+    if (!SDL_size_mul_check_overflow(rect->w, bpp, &row_size) ||
+        !SDL_size_mul_check_overflow(rect->h, row_size, &image_size)) {
+        SDL_SetError("read size overflow");
+        return NULL;
+    }
 
     SDL_Surface *surface = SDL_CreateSurface(rect->w, rect->h, pixfmt);
 
@@ -863,7 +873,7 @@ static SDL_Surface *GPU_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect
 
     SDL_GPUTransferBufferCreateInfo tbci;
     SDL_zero(tbci);
-    tbci.sizeInBytes = image_size;
+    tbci.sizeInBytes = (Uint32)image_size;
     tbci.usage = SDL_GPU_TRANSFERBUFFERUSAGE_DOWNLOAD;
 
     SDL_GPUTransferBuffer *tbuf = SDL_CreateGPUTransferBuffer(data->device, &tbci);
@@ -899,7 +909,7 @@ static SDL_Surface *GPU_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect
 
     void *mapped_tbuf = SDL_MapGPUTransferBuffer(data->device, tbuf, false);
 
-    if (surface->pitch == row_size) {
+    if ((size_t)surface->pitch == row_size) {
         memcpy(surface->pixels, mapped_tbuf, image_size);
     } else {
         Uint8 *input = mapped_tbuf;
@@ -935,7 +945,11 @@ static bool CreateBackbuffer(GPU_RenderData *data, Uint32 w, Uint32 h, SDL_GPUTe
     data->backbuffer.height = h;
     data->backbuffer.format = fmt;
 
-    return (bool)data->backbuffer.texture;
+    if (!data->backbuffer.texture) {
+        return false;
+    }
+
+    return true;
 }
 
 static bool GPU_RenderPresent(SDL_Renderer *renderer)
diff --git a/src/render/sdlgpu/SDL_shaders_gpu.c b/src/render/sdlgpu/SDL_shaders_gpu.c
index ecf44d3edded5..1b60b7c6a41bb 100644
--- a/src/render/sdlgpu/SDL_shaders_gpu.c
+++ b/src/render/sdlgpu/SDL_shaders_gpu.c
@@ -83,7 +83,7 @@ typedef struct GPU_ShaderSources
     IF_VULKAN(.spirv = { code, sizeof(code), SDL_GPU_SHADERFORMAT_SPIRV }, )
 
 #define SHADER_DXBC50(code) \
-    IF_D3D11(.dxbc50 = { code, sizeof(code), SDL_GPU_SHADERFORMAT_DXBC }, )
+    IF_D3D11(.dxbc50 = { (const unsigned char *)code, sizeof(code), SDL_GPU_SHADERFORMAT_DXBC }, )
 
 #define SHADER_DXIL60(code) \
     IF_D3D12(.dxil60 = { code, sizeof(code), SDL_GPU_SHADERFORMAT_DXIL }, )
diff --git a/src/render/sdlgpu/shaders/color.frag.sm50.dxbc.h b/src/render/sdlgpu/shaders/color.frag.sm50.dxbc.h
index 967cb66418aef..60e6b7214931a 100644
--- a/src/render/sdlgpu/shaders/color.frag.sm50.dxbc.h
+++ b/src/render/sdlgpu/shaders/color.frag.sm50.dxbc.h
@@ -1,4 +1,4 @@
-const unsigned char color_frag_sm50_dxbc[] =
+const signed char color_frag_sm50_dxbc[] =
 {
   68,  88,  66,  67, 114,-117,
 -124,  82, -97,  76, -66, -74,
@@ -82,4 +82,4 @@ const unsigned char color_frag_sm50_dxbc[] =
    0,   0,   0,   0,   0,   0,
    0,   0,   0,   0,   0,   0,
    0,   0
-};
\ No newline at end of file
+};
diff --git a/src/render/sdlgpu/shaders/linepoint.vert.sm50.dxbc.h b/src/render/sdlgpu/shaders/linepoint.vert.sm50.dxbc.h
index 97c110ce58bc5..b58bd184771c2 100644
--- a/src/render/sdlgpu/shaders/linepoint.vert.sm50.dxbc.h
+++ b/src/render/sdlgpu/shaders/linepoint.vert.sm50.dxbc.h
@@ -1,4 +1,4 @@
-const unsigned char linepoint_vert_sm50_dxbc[] =
+const signed char linepoint_vert_sm50_dxbc[] =
 {
   68,  88,  66,  67,   0, 119,
  101, -18, 103, 113,  34,  52,
@@ -169,4 +169,4 @@ const unsigned char linepoint_vert_sm50_dxbc[] =
    0,   0,   0,   0,   0,   0,
    0,   0,   0,   0,   0,   0,
    0,   0,   0,   0
-};
\ No newline at end of file
+};
diff --git a/src/render/sdlgpu/shaders/texture_rgb.frag.sm50.dxbc.h b/src/render/sdlgpu/shaders/texture_rgb.frag.sm50.dxbc.h
index 16d75e1fbfc2f..6f4088981afe4 100644
--- a/src/render/sdlgpu/shaders/texture_rgb.frag.sm50.dxbc.h
+++ b/src/render/sdlgpu/shaders/texture_rgb.frag.sm50.dxbc.h
@@ -1,4 +1,4 @@
-const unsigned char texture_rgb_frag_sm50_dxbc[] =
+const signed char texture_rgb_frag_sm50_dxbc[] =
 {
   68,  88,  66,  67, -22, -54,
  -48,  73, -47, -40, -92, -21,
@@ -120,4 +120,4 @@ const unsigned char texture_rgb_frag_sm50_dxbc[] =
    0,   0,   0,   0,   0,   0,
    0,   0,   0,   0,   0,   0,
    0,   0
-};
\ No newline at end of file
+};
diff --git a/src/render/sdlgpu/shaders/texture_rgba.frag.sm50.dxbc.h b/src/render/sdlgpu/shaders/texture_rgba.frag.sm50.dxbc.h
index 60e79c9b1837d..3b11a27d51ed2 100644
--- a/src/render/sdlgpu/shaders/texture_rgba.frag.sm50.dxbc.h
+++ b/src/render/sdlgpu/shaders/texture_rgba.frag.sm50.dxbc.h
@@ -1,4 +1,4 @@
-const unsigned char texture_rgba_frag_sm50_dxbc[] =
+const signed char texture_rgba_frag_sm50_dxbc[] =
 {
   68,  88,  66,  67, -83, 124,
   -3, -84,-102, 126,  29, -62,
@@ -117,4 +117,4 @@ const unsigned char texture_rgba_frag_sm50_dxbc[] =
    0,   0,   0,   0,   0,   0,
    0,   0,   0,   0,   0,   0
 
-};
\ No newline at end of file
+};
diff --git a/src/render/sdlgpu/shaders/tri_color.vert.sm50.dxbc.h b/src/render/sdlgpu/shaders/tri_color.vert.sm50.dxbc.h
index 4791c3b04cb7d..35c62a936b890 100644
--- a/src/render/sdlgpu/shaders/tri_color.vert.sm50.dxbc.h
+++ b/src/render/sdlgpu/shaders/tri_color.vert.sm50.dxbc.h
@@ -1,4 +1,4 @@
-const unsigned char tri_color_vert_sm50_dxbc[] =
+const signed char tri_color_vert_sm50_dxbc[] =
 {
   68,  88,  66,  67, -99,  -1,
  -83, -50,  75, -96,  -1,  28,
@@ -175,4 +175,4 @@ const unsigned char tri_color_vert_sm50_dxbc[] =
    0,   0,   0,   0,   0,   0,
    0,   0,   0,   0,   0,   0
 
-};
\ No newline at end of file
+};
diff --git a/src/render/sdlgpu/shaders/tri_texture.vert.sm50.dxbc.h b/src/render/sdlgpu/shaders/tri_texture.vert.sm50.dxbc.h
index 776ba33fa46bf..d4e68b9a997fb 100644
--- a/src/render/sdlgpu/shaders/tri_texture.vert.sm50.dxbc.h
+++ b/src/render/sdlgpu/shaders/tri_texture.vert.sm50.dxbc.h
@@ -1,4 +1,4 @@
-const unsigned char tri_texture_vert_sm50_dxbc[] =
+const signed char tri_texture_vert_sm50_dxbc[] =
 {
   68,  88,  66,  67, 108, 113,
 -108,  81,  -2,  27,  41,  94,
@@ -192,4 +192,4 @@ const unsigned char tri_texture_vert_sm50_dxbc[] =
    0,   0,   0,   0,   0,   0,
    0,   0,   0,   0,   0,   0,
    0,   0
-};
\ No newline at end of file
+};