From f10f8bc9c5c5c6ee19df753889d6caaa8b7371e4 Mon Sep 17 00:00:00 2001 From: Bill Beech Date: Mon, 13 Mar 2017 16:55:13 -0700 Subject: [PATCH] SWTP6800: Address Converity identified problems --- swtp6800/common/bootrom.c | 4 ++++ swtp6800/common/dc-4.c | 20 +++++++++++++++++--- swtp6800/common/mp-b2.c | 11 +++++++++-- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/swtp6800/common/bootrom.c b/swtp6800/common/bootrom.c index d081c749..148a17f6 100644 --- a/swtp6800/common/bootrom.c +++ b/swtp6800/common/bootrom.c @@ -142,6 +142,10 @@ t_stat BOOTROM_attach (UNIT *uptr, CONST char *cptr) return r; } image_size = (t_addr)sim_fsize_ex (BOOTROM_unit.fileref); + if (image_size <= 0) { + sim_printf("BOOTROM_attach: File error\n"); + return SCPE_IOERR; + } for (capac = 0x200, i=1; capac < image_size; capac <<= 1, i++); if (i > (UNIT_2764>>UNIT_V_MSIZE)) { detach_unit (uptr); diff --git a/swtp6800/common/dc-4.c b/swtp6800/common/dc-4.c index 0da08b43..a0451659 100644 --- a/swtp6800/common/dc-4.c +++ b/swtp6800/common/dc-4.c @@ -374,6 +374,7 @@ t_stat dsk_reset (DEVICE *dptr) int32 fdcdrv(int32 io, int32 data) { static long pos; + static int32 err; if (io) { /* write to DC-4 drive register */ sim_debug (DEBUG_write, &dsk_dev, "\nfdcdrv: Drive selected %d cur_dsk=%d", @@ -392,7 +393,11 @@ int32 fdcdrv(int32 io, int32 data) pos = 0x200; /* Read in SIR */ sim_debug (DEBUG_read, &dsk_dev, "\nfdcdrv: Read pos = %ld ($%04X)", pos, (unsigned int) pos); - sim_fseek(dsk_unit[cur_dsk].fileref, pos, SEEK_SET); /* seek to offset */ + err = sim_fseek(dsk_unit[cur_dsk].fileref, pos, SEEK_SET); /* seek to offset */ + if (err) { + sim_printf("\nfdccmd: File error\n"); + return SCPE_IOERR; + } sim_fread(dsk_unit[cur_dsk].filebuf, SECSIZ, 1, dsk_unit[cur_dsk].fileref); /* read in buffer */ dsk_unit[cur_dsk].u3 |= BUSY | DRQ; /* set DRQ & BUSY */ dsk_unit[cur_dsk].pos = 0; /* clear counter */ @@ -416,6 +421,7 @@ int32 fdccmd(int32 io, int32 data) { static int32 val = 0, val1 = NOTRDY; static long pos; + static int32 err; if ((dsk_unit[cur_dsk].flags & UNIT_ATT) == 0) { /* not attached */ dsk_unit[cur_dsk].u3 |= NOTRDY; /* set not ready flag */ @@ -434,7 +440,11 @@ int32 fdccmd(int32 io, int32 data) pos += SECSIZ * (dsk_unit[cur_dsk].u5 - 1); sim_debug (DEBUG_read, &dsk_dev, "\nfdccmd: Read pos = %ld ($%08X)", pos, (unsigned int) pos); - sim_fseek(dsk_unit[cur_dsk].fileref, pos, SEEK_SET); /* seek to offset */ + err = sim_fseek(dsk_unit[cur_dsk].fileref, pos, SEEK_SET); /* seek to offset */ + if (err) { + sim_printf("\nfdccmd: File error\n"); + return SCPE_IOERR; + } sim_fread(dsk_unit[cur_dsk].filebuf, SECSIZ, 1, dsk_unit[cur_dsk].fileref); /* read in buffer */ dsk_unit[cur_dsk].u3 |= BUSY | DRQ; /* set DRQ & BUSY */ dsk_unit[cur_dsk].pos = 0; /* clear counter */ @@ -449,7 +459,11 @@ int32 fdccmd(int32 io, int32 data) pos += SECSIZ * (dsk_unit[cur_dsk].u5 - 1); sim_debug (DEBUG_write, &dsk_dev, "\nfdccmd: Write pos = %ld ($%08X)", pos, (unsigned int) pos); - sim_fseek(dsk_unit[cur_dsk].fileref, pos, SEEK_SET); /* seek to offset */ + err = sim_fseek(dsk_unit[cur_dsk].fileref, pos, SEEK_SET); /* seek to offset */ + if (err) { + sim_printf("\nfdccmd: File error\n"); + return SCPE_IOERR; + } wrt_flag = 1; /* set write flag */ dsk_unit[cur_dsk].u3 |= BUSY | DRQ;/* set DRQ & BUSY */ dsk_unit[cur_dsk].pos = 0; /* clear counter */ diff --git a/swtp6800/common/mp-b2.c b/swtp6800/common/mp-b2.c index f4fc0790..71bc08d8 100644 --- a/swtp6800/common/mp-b2.c +++ b/swtp6800/common/mp-b2.c @@ -187,12 +187,13 @@ int32 MB_get_mbyte(int32 addr) case 0x1000: if (MB_unit.flags & UNIT_RAM_0000) { val = mp_8m_get_mbyte(addr) & 0xFF; - sim_debug (DEBUG_read, &MB_dev, "MB_get_mbyte: addr=%04X\n", addr); + sim_debug (DEBUG_read, &MB_dev, "MB_get_mbyte: addr=%04X\n", addr); if (MB_dev.dctrl & DEBUG_read) printf("MB_get_mbyte: mp_8m val=%02X\n", val); return val; } else return 0xFF; + /* fall through */ case 0x2000: case 0x3000: if (MB_unit.flags & UNIT_RAM_2000) { @@ -201,16 +202,18 @@ int32 MB_get_mbyte(int32 addr) return val; } else return 0xFF; + /* fall through */ case 0x4000: case 0x5000: if (MB_unit.flags & UNIT_RAM_4000) { val = mp_8m_get_mbyte(addr) & 0xFF; - sim_debug (DEBUG_read, &MB_dev, "MB_get_mbyte: addr=%04X\n", addr); + sim_debug (DEBUG_read, &MB_dev, "MB_get_mbyte: addr=%04X\n", addr); if (MB_dev.dctrl & DEBUG_read) printf("MB_get_mbyte: mp_8m val=%02X\n", val); return val; } else return 0xFF; + /* fall through */ case 0x6000: case 0x7000: if (MB_unit.flags & UNIT_RAM_6000) { @@ -219,6 +222,7 @@ int32 MB_get_mbyte(int32 addr) return val; } else return 0xFF; + /* fall through */ case 0x8000: if (addr < 0x8020) val = (dev_table[addr - 0x8000].routine(0, 0)) & 0xFF; @@ -227,6 +231,7 @@ int32 MB_get_mbyte(int32 addr) sim_debug (DEBUG_read, &MB_dev, "MB_get_mbyte: I/O addr=%04X val=%02X\n", addr, val); return val; + /* fall through */ case 0xA000: case 0xB000: if (MB_unit.flags & UNIT_RAM_A000) { @@ -235,6 +240,7 @@ int32 MB_get_mbyte(int32 addr) return val; } else return 0xFF; + /* fall through */ case 0xC000: case 0xD000: if (MB_unit.flags & UNIT_RAM_C000) { @@ -243,6 +249,7 @@ int32 MB_get_mbyte(int32 addr) return val; } else return 0xFF; + /* fall through */ default: return 0xFF; }