From d960c96f562a221d8d57db4d186bbcda287987b2 Mon Sep 17 00:00:00 2001 From: Mark Pizzolato Date: Mon, 14 Feb 2022 19:30:30 -0800 Subject: [PATCH] SCP: UNIT_BUFABLE isn't always set with UNIT_MUSTBUF UNIT_BUFABLE without UNIT_MUSTBUF means that uptr->filebuf is managed outside of attach_unit's authority. The buffer copy must always be allocated if UNIT_BUFABLE is set so that there is space to store the initial loaded copy. Fix #1122 --- scp.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/scp.c b/scp.c index 5e6c4239..916f8934 100644 --- a/scp.c +++ b/scp.c @@ -8154,16 +8154,18 @@ else { } if (uptr->flags & UNIT_BUFABLE) { /* buffer? */ uint32 cap = ((uint32) uptr->capac) / dptr->aincr; /* effective size */ + + uptr->filebuf2 = calloc (cap, SZ_D (dptr)); /* allocate copy */ + if (uptr->filebuf2 == NULL) + return attach_err (uptr, SCPE_MEM); /* error */ if (uptr->flags & UNIT_MUSTBUF) { /* dyn alloc? */ uptr->filebuf = calloc (cap, SZ_D (dptr)); /* allocate */ - uptr->filebuf2 = calloc (cap, SZ_D (dptr)); /* allocate copy */ - if ((uptr->filebuf == NULL) || /* no buffer? */ - (uptr->filebuf2 == NULL)) { + if (uptr->filebuf == NULL) { free (uptr->filebuf); uptr->filebuf = NULL; free (uptr->filebuf2); uptr->filebuf2 = NULL; - return attach_err (uptr, SCPE_MEM); /* error */ + return attach_err (uptr, SCPE_MEM); /* error */ } } sim_messagef (SCPE_OK, "%s: buffering file in memory\n", sim_uname (uptr));