From: John Tsiombikas Date: Tue, 13 Dec 2022 04:26:46 +0000 (+0200) Subject: fix 64bit bug: crash in png loading X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=summerhack;a=commitdiff_plain;h=21cb5f9bccf9d04d686e3126bfd7510dfa554d88 fix 64bit bug: crash in png loading --- diff --git a/Makefile b/Makefile index d5f022e..bc33ff8 100644 --- a/Makefile +++ b/Makefile @@ -13,10 +13,11 @@ CXXFLAGS = -ansi -pedantic -Wall $(opt) -Isrc/3dengfx/src -MMD `sdl-config --cfl CFLAGS = -std=c89 -pedantic -Wall $(opt) -MMD `sdl-config --cflags` libs = src/3dengfx/lib3dengfx.a `sdl-config --libs` -lGL -lvorbisfile -ljpeg -lpng -lz -$(bin): $(obj) src/3dengfx/lib3dengfx.a +$(bin): $(obj) 3dengfx $(CXX) -o $@ $(obj) $(libs) -src/3dengfx/lib3dengfx.a: +.PHONY: 3dengfx +3dengfx: $(MAKE) -C src/3dengfx -include $(obj:.o=.d) diff --git a/src/3dengfx/src/gfx/image_png.c b/src/3dengfx/src/gfx/image_png.c index 1b0f759..47f1650 100644 --- a/src/3dengfx/src/gfx/image_png.c +++ b/src/3dengfx/src/gfx/image_png.c @@ -51,6 +51,7 @@ void *load_png(FILE *fp, unsigned long *xsz, unsigned long *ysz) { png_info *info_ptr; int i; uint32_t **lineptr, *pixels; + uint32_t width, height; int channel_bits, color_type, ilace_type, compression, filtering; if(!(png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0))) { @@ -75,7 +76,9 @@ void *load_png(FILE *fp, unsigned long *xsz, unsigned long *ysz) { png_read_png(png_ptr, info_ptr, PNG_TRANSFORM_BGR, 0); - png_get_IHDR(png_ptr, info_ptr, xsz, ysz, &channel_bits, &color_type, &ilace_type, &compression, &filtering); + png_get_IHDR(png_ptr, info_ptr, &width, &height, &channel_bits, &color_type, &ilace_type, &compression, &filtering); + *xsz = width; + *ysz = height; pixels = malloc(*xsz * *ysz * sizeof(uint32_t)); lineptr = (uint32_t**)png_get_rows(png_ptr, info_ptr);