From 2ef48bea8aad4d2e2d7450eff71b0adb6bb2ac44 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Sun, 26 Jan 2020 23:59:04 +0000 Subject: [PATCH] Change DecodeBitmap to use unsigned ints Why would an image decoder ever return a _negative_ image width/height? --- src/Bitmap.cpp | 4 ++-- src/Bitmap.h | 2 +- src/Draw.cpp | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Bitmap.cpp b/src/Bitmap.cpp index 264a02db..589509c9 100644 --- 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) diff --git a/src/Bitmap.h b/src/Bitmap.h index b8038784..c59c3d6e 100644 --- a/src/Bitmap.h +++ b/src/Bitmap.h @@ -2,5 +2,5 @@ #include -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); diff --git a/src/Draw.cpp b/src/Draw.cpp index aeb680bc..fb768a25 100644 --- a/src/Draw.cpp +++ b/src/Draw.cpp @@ -223,7 +223,7 @@ BOOL MakeSurface_Resource(const char *name, SurfaceID surf_no) 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 @@ BOOL MakeSurface_File(const char *name, SurfaceID surf_no) return FALSE; } - int width, height; + unsigned int width, height; unsigned char *image_buffer = DecodeBitmap(data, size, &width, &height); free(data); @@ -339,7 +339,7 @@ BOOL ReloadBitmap_Resource(const char *name, SurfaceID surf_no) 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 @@ BOOL ReloadBitmap_File(const char *name, SurfaceID surf_no) return FALSE; } - int width, height; + unsigned int width, height; unsigned char *image_buffer = DecodeBitmap(data, size, &width, &height); free(data);