From 7d2a5cdbc134ca7047ca13c57af600292e10ffee Mon Sep 17 00:00:00 2001 From: Eric Carr Date: Sun, 16 Nov 2025 01:51:17 -0600 Subject: [PATCH] CoCo: Fix memory overflow bug and "macro redfined" warning --- Changelog.md | 3 +++ Makefile | 5 ----- common/src/fn_fuji/fuji_set_appkey_details.c | 7 +++++-- makefiles/compiler-cmoc.mk | 2 +- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/Changelog.md b/Changelog.md index de812f2..6486343 100644 --- a/Changelog.md +++ b/Changelog.md @@ -2,6 +2,9 @@ ## [Unreleased] +- [coco] Fix bug in fuji_set_appkey_details that overwrote the first byte of data of a project that includes fujinet-lib +- [coco] Remove unneccesary makefile block for mac - make runs fine on mac +- [coco] Removed legacy -D_CMOC_VERSION_=1 CFLAG, which floods output with "macro redefined" warnings. CMOC already defines this. - [build] Guarded hex_dump.c with flag `FN_LIB_DEBUG` which can be enabled via `application.mk`. Added additional docs to `README.md` to explain this. Added comments to top of `build.mk` to explain a little bit about paths that are included. diff --git a/Makefile b/Makefile index 8dfdf58..6b1ed80 100644 --- a/Makefile +++ b/Makefile @@ -3,11 +3,6 @@ # Set the TARGETS and PROGRAM values as required. # See makefiles/build.mk for details on directory structure for src files and how to add custom extensions to the build. -# Require GNU Make 4.0 or later for $(file ...) function -ifeq ($(filter 4.%,$(MAKE_VERSION)),) - $(error This Makefile requires GNU Make 4.0 or later. You are using $(MAKE_VERSION). Please use 'gmake' instead of 'make' on macOS.) -endif - TARGETS = adam apple2 apple2enh atari c64 coco msdos PROGRAM := fujinet.lib diff --git a/common/src/fn_fuji/fuji_set_appkey_details.c b/common/src/fn_fuji/fuji_set_appkey_details.c index 0801978..de5356a 100644 --- a/common/src/fn_fuji/fuji_set_appkey_details.c +++ b/common/src/fn_fuji/fuji_set_appkey_details.c @@ -9,11 +9,14 @@ extern uint16_t ak_creator_id; extern uint8_t ak_app_id; -extern enum AppKeySize ak_appkey_size; + +// IMPORTANT: Instead of "enum AppKeySize", explicitly matching the underlying uint8_t data type, othwerise +// CMOC will write a 16 bit enum value at the location, overflowing into the next byte, causing corruption +extern uint8_t ak_appkey_size; void fuji_set_appkey_details(uint16_t creator_id, uint8_t app_id, enum AppKeySize keysize) { - ak_appkey_size = keysize; + ak_appkey_size = (uint8_t)keysize; ak_app_id = app_id; ak_creator_id = creator_id; } diff --git a/makefiles/compiler-cmoc.mk b/makefiles/compiler-cmoc.mk index 135cbb0..21a6544 100644 --- a/makefiles/compiler-cmoc.mk +++ b/makefiles/compiler-cmoc.mk @@ -1,6 +1,6 @@ CC := cmoc AR := lwar -CFLAGS := -O2 -D_CMOC_VERSION_=1 +CFLAGS := -O2 INCC_ARG := -I INCS_ARG := -I