CARD: Fix potential NULL pointer dereference

As reported in #920
This commit is contained in:
Mark Pizzolato 2020-08-15 12:24:57 -07:00
parent 4a686ad0d0
commit 272bbd4551

View file

@ -1353,27 +1353,39 @@ sim_card_detach(UNIT * uptr)
t_stat sim_card_attach_help(FILE *st, DEVICE *dptr, UNIT *uptr, int32 flag, const char *cptr) t_stat sim_card_attach_help(FILE *st, DEVICE *dptr, UNIT *uptr, int32 flag, const char *cptr)
{ {
fprintf (st, "%s Card %sAttach Help\n\n", dptr->name, (uptr->flags & UNIT_RO) ? "Reader " : "Punch "); uint32 i, readers = 0, punches = 0;
for (i=0; i < dptr->numunits; ++i)
if (dptr->units[i].flags & UNIT_ATTABLE) {
readers += ((dptr->units[i].flags & UNIT_RO) != 0);
punches += ((dptr->units[i].flags & UNIT_RO) == 0);
}
if (uptr == NULL)
uptr = dptr->units;
fprintf (st, "%s Card %s%s%sAttach Help\n\n", dptr->name,
readers ? "Reader " : "", readers & punches ? "& " : "", punches ? "Punch ": "");
if (0 == (uptr-dptr->units)) { if (0 == (uptr-dptr->units)) {
if (dptr->numunits > 1) { if (dptr->numunits > 1) {
uint32 i; uint32 i;
for (i=0; i < dptr->numunits; ++i) for (i=0; i < dptr->numunits; ++i)
if (dptr->units[i].flags & UNIT_ATTABLE) if (dptr->units[i].flags & UNIT_ATTABLE)
fprintf (st, " sim> ATTACH {switches} %s%d carddeck\n\n", dptr->name, i); fprintf (st, " sim> ATTACH {switches} %s carddeck\n", sim_uname (&dptr->units[i]));
fprintf (st, "\n");
} }
else else
fprintf (st, " sim> ATTACH {switches} %s carddeck\n\n", dptr->name); fprintf (st, " sim> ATTACH {switches} %s carddeck\n\n", sim_uname (uptr));
} }
else else
fprintf (st, " sim> ATTACH {switches} %s carddeck\n\n", dptr->name); fprintf (st, " sim> ATTACH {switches} %s carddeck\n\n", sim_uname (uptr));
fprintf (st, "Attach command switches\n"); fprintf (st, "Attach command switches\n");
fprintf (st, " -F Open the indicated card deck in a specific format (default\n"); fprintf (st, " -F Open the indicated card deck in a specific format (default\n");
fprintf (st, " is AUTO, alternatives are BIN, TEXT, BCD and CBN)\n"); fprintf (st, " is AUTO, alternatives are BIN, TEXT, BCD and CBN)\n");
if ((uptr->flags & UNIT_RO) == 0) { if (punches != 0) {
fprintf (st, " -N Create a new punch output file (default is to append to\n"); fprintf (st, " -N Create a new punch output file (default is to append to\n");
fprintf (st, " an existing file if it exists)\n"); fprintf (st, " an existing file if it exists)\n");
} else { }
if (readers != 0) {
fprintf (st, " -E Return EOF after deck read\n"); fprintf (st, " -E Return EOF after deck read\n");
fprintf (st, " -S Append deck to cards currently waiting to be read\n"); fprintf (st, " -S Append deck to cards currently waiting to be read\n");
} }