shithub: cstory

Download patch

ref: 2ef48bea8aad4d2e2d7450eff71b0adb6bb2ac44
parent: 4f7bd116f60a40ebde7202e7fc8fdfe91ba41389
author: Clownacy <Clownacy@users.noreply.github.com>
date: Sun Jan 26 18:59:04 EST 2020

Change DecodeBitmap to use unsigned ints

Why would an image decoder ever return a _negative_ image
width/height?

--- a/src/Bitmap.cpp
+++ b/src/Bitmap.cpp
@@ -8,9 +8,9 @@
 #define STBI_NO_LINEAR
 #include "stb_image.h"
 
-unsigned char* DecodeBitmap(const unsigned char *in_buffer, size_t in_buffer_size, int *width, int *height)
+unsigned char* DecodeBitmap(const unsigned char *in_buffer, size_t in_buffer_size, unsigned int *width, unsigned int *height)
 {
-	return stbi_load_from_memory(in_buffer, in_buffer_size, width, height, NULL, 3);
+	return stbi_load_from_memory(in_buffer, in_buffer_size, (int*)width, (int*)height, NULL, 3);
 }
 
 void FreeBitmap(unsigned char *buffer)
--- a/src/Bitmap.h
+++ b/src/Bitmap.h
@@ -2,5 +2,5 @@
 
 #include <stddef.h>
 
-unsigned char* DecodeBitmap(const unsigned char *in_buffer, size_t in_buffer_size, int *width, int *height);
+unsigned char* DecodeBitmap(const unsigned char *in_buffer, size_t in_buffer_size, unsigned int *width, unsigned int *height);
 void FreeBitmap(unsigned char *buffer);
--- a/src/Draw.cpp
+++ b/src/Draw.cpp
@@ -223,7 +223,7 @@
 	if (data == NULL)
 		return FALSE;
 
-	int width, height;
+	unsigned int width, height;
 	unsigned char *image_buffer = DecodeBitmap(data, size, &width, &height);
 
 	if (image_buffer == NULL)
@@ -291,7 +291,7 @@
 		return FALSE;
 	}
 
-	int width, height;
+	unsigned int width, height;
 	unsigned char *image_buffer = DecodeBitmap(data, size, &width, &height);
 
 	free(data);
@@ -339,7 +339,7 @@
 	if (data == NULL)
 		return FALSE;
 
-	int width, height;
+	unsigned int width, height;
 	unsigned char *image_buffer = DecodeBitmap(data, size, &width, &height);
 
 	if (!ScaleAndUploadSurface(image_buffer, width, height, surf_no))
@@ -387,7 +387,7 @@
 		return FALSE;
 	}
 
-	int width, height;
+	unsigned int width, height;
 	unsigned char *image_buffer = DecodeBitmap(data, size, &width, &height);
 
 	free(data);
--