From 81957f8b8252eb00ebf2be177677fd2c7b1d58d0 Mon Sep 17 00:00:00 2001
From: Anonymous Maarten <[EMAIL REDACTED]>
Date: Thu, 5 Jan 2023 23:17:00 +0100
Subject: [PATCH] Fix -Wsign-compare warnings in IMG_xcf.c and IMG_xpm.c
---
IMG_xcf.c | 7 +++++--
IMG_xpm.c | 8 ++++----
2 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/IMG_xcf.c b/IMG_xcf.c
index af92e355..66fd452f 100644
--- a/IMG_xcf.c
+++ b/IMG_xcf.c
@@ -536,7 +536,8 @@ static unsigned char * load_xcf_tile_none (SDL_RWops * src, Uint64 len, int bpp,
load = (unsigned char *) SDL_malloc ((size_t)len); // expect this is okay
}
if (load != NULL) {
- if (SDL_RWread(src, load, len) != len) {
+ Sint64 read = SDL_RWread(src, load, len);
+ if (read < 0 || (Uint64)read != len) {
SDL_free(load);
load = NULL;
}
@@ -548,6 +549,7 @@ static unsigned char * load_xcf_tile_rle (SDL_RWops * src, Uint64 len, int bpp,
unsigned char * load, * t, * data, * d;
int i, size, j, length;
unsigned char val;
+ Sint64 read;
if (len == 0 || len > (Uint64)SDL_SIZE_MAX) { /* probably bogus data. */
return NULL;
@@ -557,7 +559,8 @@ static unsigned char * load_xcf_tile_rle (SDL_RWops * src, Uint64 len, int bpp,
if (load == NULL)
return NULL;
- if ( SDL_RWread(src, t, len) != len ) {
+ read = SDL_RWread(src, load, len);
+ if (read < 0 || (Uint64)read != len) {
SDL_free(load);
return NULL;
}
diff --git a/IMG_xpm.c b/IMG_xpm.c
index f6aae063..4ff5b9bf 100644
--- a/IMG_xpm.c
+++ b/IMG_xpm.c
@@ -116,7 +116,7 @@ static struct color_hash *create_colorhash(int maxnum)
bytes = hash->size * sizeof(struct hash_entry **);
/* Check for overflow */
- if ((bytes / sizeof(struct hash_entry **)) != hash->size) {
+ if ((bytes / sizeof(struct hash_entry **)) != (Uint32)hash->size) {
IMG_SetError("memory allocation overflow");
SDL_free(hash);
return NULL;
@@ -129,7 +129,7 @@ static struct color_hash *create_colorhash(int maxnum)
bytes = maxnum * sizeof(struct hash_entry);
/* Check for overflow */
- if ((bytes / sizeof(struct hash_entry)) != maxnum) {
+ if ((bytes / sizeof(struct hash_entry)) != (Uint32)maxnum) {
IMG_SetError("memory allocation overflow");
SDL_free(hash->table);
SDL_free(hash);
@@ -902,7 +902,7 @@ static int color_to_argb(char *spec, int speclen, Uint32 *argb)
*argb = 0xff000000 | (Uint32)SDL_strtol(buf, NULL, 16);
return 1;
} else {
- int i;
+ size_t i;
for (i = 0; i < SDL_arraysize(known); i++) {
if (SDL_strncasecmp(known[i].name, spec, speclen) == 0) {
*argb = known[i].argb;
@@ -1039,7 +1039,7 @@ static SDL_Surface *load_xpm(char **xpm, SDL_RWops *src, SDL_bool force_32bit)
}
/* Check for allocation overflow */
- if ((size_t)(ncolors * cpp)/cpp != ncolors) {
+ if ((size_t)((Uint32)ncolors * cpp)/cpp != (Uint32)ncolors) {
error = "Invalid color specification";
goto done;
}