changeset 302:f09c166fd4d4

core: fix zfile_close crash While here add compression support into Makefile.
author David Demelier <markand@malikania.fr>
date Thu, 24 Jun 2021 20:22:47 +0200
parents f04b4ee04db3
children 48a09c9d3d00
files GNUmakefile libmlk-core/core/zfile.c
diffstat 2 files changed, 21 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/GNUmakefile	Wed Jun 23 22:41:34 2021 +0200
+++ b/GNUmakefile	Thu Jun 24 20:22:47 2021 +0200
@@ -29,6 +29,7 @@
 
 # Compile time options.
 NLS=                    1
+COMPRESS=               1
 
 LIBMLK_SQLITE=          extern/libsqlite/libmlk-sqlite.a
 LIBMLK_SQLITE_SRCS=     extern/libsqlite/sqlite3.c
@@ -230,8 +231,17 @@
 SED.nls=                /@define WITH_NLS@/d
 endif
 
+# Can't use standard input otherwise frame content size isn't available.
+ifeq (${COMPRESS},1)
+TILESET.cmd=            ${MLK_TILESET} < $< > $@.tmp && zstd -17 $@.tmp --rm -fqo $@
+MAP.cmd=                ${MLK_MAP} < $< > $@.tmp && zstd -17 $@.tmp --rm -fqo $@
+else
+TILESET.cmd=            ${MLK_TILESET} < $< > $@
+MAP.cmd=                ${MLK_MAP} < $< > $@
+endif
+
 .SUFFIXES:
-.SUFFIXES: .c .o .h .map .ogg .png .sql .tileset .ttf
+.SUFFIXES: .c .o .h .json .map .ogg .png .sql .tileset .ttf
 
 all: ${TARGETS}
 
@@ -253,14 +263,15 @@
 	@echo "BCC  $<"
 	@${MLK_BCC} -0csu $< assets_$(notdir $<) > $@
 
-# Maps
+# Maps.
 .json.map:
 	@echo "MAP  $<"
-	@${MLK_MAP} < $< > $@
+	@${MAP.cmd}
 
-.tileset.map:
+# Tilesets.
+.json.tileset:
 	@echo "TS   $<"
-	@${MLK_TILESET} < $< > $@
+	@${TILESET.cmd}
 
 -include ${LIBMLK_ADVENTURE_DEPS}
 -include ${LIBMLK_CORE_DEPS}
--- a/libmlk-core/core/zfile.c	Wed Jun 23 22:41:34 2021 +0200
+++ b/libmlk-core/core/zfile.c	Thu Jun 24 20:22:47 2021 +0200
@@ -20,6 +20,7 @@
 #include <assert.h>
 #include <errno.h>
 #include <fcntl.h>
+#include <stdint.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
@@ -121,6 +122,9 @@
 	assert(zf);
 
 	free(zf->data);
-	fclose(zf->fp);
+
+	if (zf->fp)
+		fclose(zf->fp);
+
 	memset(zf, 0, sizeof (*zf));
 }