From a2f089e1f1196168064b3fa4a2a94e6618d3ee3a Mon Sep 17 00:00:00 2001 From: David Griffith Date: Tue, 23 May 2023 00:00:02 -0700 Subject: [PATCH] Fixed brain-dead handling of undo slots. The manpages have always mentioned a default number of undo slots as being 20 (curses interface) or 25 (X11 interface). The problem is that nowhere is this actually set. This commit makes the Frotz core actually set a default of 25. There is no need to involve the interface code. --- ChangeLog | 2 ++ doc/frotz.6 | 2 +- src/common/fastmem.c | 9 ++++++++- src/common/frotz.h | 3 +++ 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index c63d188..c60855b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -11,6 +11,8 @@ NEW FEATURES BUG FIXES +- Fixed brain-dead handling of undo slots. + - Fixed a segfault when xfrotz detects a fatal error. - Fixed compile failure of the SDL interface for GCC 12 and maybe GCC 11. diff --git a/doc/frotz.6 b/doc/frotz.6 index 91310fc..f0b0e00 100644 --- a/doc/frotz.6 +++ b/doc/frotz.6 @@ -205,7 +205,7 @@ toned down. .TP .B \-u N Sets the number of slots available for Frotz's multiple undo hotkey (see -below). This defaults to twenty, which should be sufficient for most +below). This defaults to 25, which should be sufficient for most purposes. Setting too high a number here may be dangerous on machines with limited memory. .TP diff --git a/src/common/fastmem.c b/src/common/fastmem.c index ede1330..c73ef98 100644 --- a/src/common/fastmem.c +++ b/src/common/fastmem.c @@ -256,7 +256,7 @@ void init_header(void) void init_setup(void) { memset(&f_setup, 0, sizeof(f_setup)); - f_setup.undo_slots = MAX_UNDO_SLOTS; + f_setup.undo_slots = DEFAULT_UNDO_SLOTS; f_setup.script_cols = 80; f_setup.err_report_mode = ERR_DEFAULT_REPORT_MODE; f_setup.blorb_file = NULL; @@ -289,6 +289,7 @@ void init_memory(void) zword addr; unsigned n; int i, j; + char errorstring[81]; #ifdef TOPS20 zword checksum = 0; @@ -458,6 +459,12 @@ void init_memory(void) }; /* INDENT-ON */ + /* Ensure undo slots don't exceed maximum */ + if (f_setup.undo_slots > MAX_UNDO_SLOTS) { + snprintf(errorstring, 80, "Maxmimum undo slots is %d", MAX_UNDO_SLOTS); + os_fatal(errorstring); + } + /* Open story file */ if ((story_fp = os_load_story()) == NULL) os_fatal("Cannot open story file"); diff --git a/src/common/frotz.h b/src/common/frotz.h index 9407367..9abae04 100644 --- a/src/common/frotz.h +++ b/src/common/frotz.h @@ -170,6 +170,9 @@ typedef struct { #include "unused.h" /*** Constants that may be set at compile time ***/ +#ifndef DEFAULT_UNDO_SLOTS +#define DEFAULT_UNDO_SLOTS 25 +#endif #ifndef MAX_UNDO_SLOTS #define MAX_UNDO_SLOTS 500 #endif -- 2.34.1