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
This commit is contained in:
Mark Pizzolato 2022-02-14 19:30:30 -08:00
parent eac0e5680b
commit d960c96f56

8
scp.c
View file

@ -8154,11 +8154,13 @@ 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);