TAPE: Fix potential crash in library unit tests

Improper declaration of state variables referenced in setjmp/longjmp.
This commit is contained in:
Larry Baker 2020-08-15 16:21:02 -07:00 committed by Mark Pizzolato
parent 272bbd4551
commit 4041894b67
3 changed files with 16 additions and 7 deletions

4
scp.c
View file

@ -15563,9 +15563,9 @@ for (i = 0; (dptr = sim_devices[i]) != NULL; i++) {
tstat = SCPE_OK; /* can't enable, just skip device */
if (tstat != SCPE_OK) {
stat = tstat;
sim_printf ("%s device tests returned: %d - %s\n", dptr->name, tstat, sim_error_text (tstat));
sim_printf ("%s device tests returned: %d - %s\n", dptr->name, SCPE_BARE_STATUS (tstat), sim_error_text (tstat));
if (sim_ttisatty()) {
if (get_yn ("Continue with additional tests? [N]", SCPE_STOP) == SCPE_STOP)
if (get_yn ("Continue with additional tests? [N] ", SCPE_STOP) == SCPE_STOP)
break;
}
else

8
scp.h
View file

@ -456,13 +456,13 @@ extern const char *sim_vm_step_unit; /* Simulator can change
These defines help implement consistent unit test functionality */
#define SIM_TEST_INIT \
int test_stat; \
const char *sim_test; \
volatile int test_stat; \
const char *volatile sim_test; \
jmp_buf sim_test_env; \
if ((test_stat = setjmp (sim_test_env))) { \
sim_printf ("Error: %d - '%s' processing: %s\n", \
test_stat, sim_error_text(test_stat), \
sim_test); \
SCPE_BARE_STATUS(test_stat), \
sim_error_text(test_stat), sim_test); \
return test_stat; \
}
#define SIM_TEST(_stat) \

View file

@ -3894,6 +3894,10 @@ sim_switches = SWMASK ('F') | (sim_switches & SWMASK ('D')) | SWMASK ('N');
if (sim_switches & SWMASK ('D'))
uptr->dctrl = MTSE_DBG_STR | MTSE_DBG_DAT;
aws_stat = sim_tape_attach_ex (uptr, name, (saved_switches & SWMASK ('D')) ? MTSE_DBG_STR | MTSE_DBG_DAT: 0, 0);
if (aws_stat != MTSE_OK) {
stat = aws_stat;
goto Done_Files;
}
sim_switches = saved_switches;
stat = SCPE_OK;
for (i=0; i<files; i++) {
@ -4025,7 +4029,8 @@ if (fTAR)
if (fTAR2)
fclose (fTAR2);
free (buf);
sim_tape_detach (uptr);
if (aws_stat == MTSE_OK)
sim_tape_detach (uptr);
if (stat == SCPE_OK) {
char name1[CBUFSIZE], name2[CBUFSIZE];
@ -4137,6 +4142,10 @@ t_stat sim_tape_test (DEVICE *dptr)
int32 saved_switches = sim_switches;
SIM_TEST_INIT;
if (dptr->units->flags & UNIT_ATT)
return sim_messagef (SCPE_ALATT, "The %s device must be detached to run the tests\n",
sim_uname(dptr->units));
sim_printf ("\nTesting %s device sim_tape APIs\n", sim_uname(dptr->units));
SIM_TEST(sim_tape_test_density_string ());