From 1cc21db79b7b59b091748dace76ac0f45759a6ce Mon Sep 17 00:00:00 2001 From: Richard Cornwell Date: Sat, 6 Oct 2018 00:24:02 -0400 Subject: [PATCH] ICL1900: Fixed coverity errors. --- ICL1900/icl1900_cpu.c | 2 +- ICL1900/icl1900_eds8.c | 1 + ICL1900/icl1900_lp.c | 2 +- ICL1900/icl1900_mt.c | 2 +- ICL1900/icl1900_mta.c | 5 ++--- ICL1900/icl1900_stdio.c | 4 ++-- ICL1900/icl1900_sys.c | 8 ++++---- ICL1900/icl1900_tp.c | 11 ++++++----- ICL1900/icl1900_tr.c | 23 +++++++++++++++++------ 9 files changed, 35 insertions(+), 23 deletions(-) diff --git a/ICL1900/icl1900_cpu.c b/ICL1900/icl1900_cpu.c index fcf46f4..7cc4e59 100644 --- a/ICL1900/icl1900_cpu.c +++ b/ICL1900/icl1900_cpu.c @@ -2408,7 +2408,7 @@ voluntary: BCarry = BV = 0; adrmask = M15; if ((cpu_flags & SV) != 0) { - if ((RF & 070) == 140 || (RF & 170) == 0110) + if ((RF & 0170) == 0140 || (RF & 0170) == 0110) XR[1] = RD+RX; XR[2] = RB; XR[3] = RF & 07; diff --git a/ICL1900/icl1900_eds8.c b/ICL1900/icl1900_eds8.c index f5a8650..9f2d0e8 100644 --- a/ICL1900/icl1900_eds8.c +++ b/ICL1900/icl1900_eds8.c @@ -630,6 +630,7 @@ eds8_attach(UNIT * uptr, CONST char *file) uptr->CYL = 0; uptr->CMD = EDS8_TERM; chan_set_done(GET_UADDR(eds8_dev.flags)); + return SCPE_OK; } diff --git a/ICL1900/icl1900_lp.c b/ICL1900/icl1900_lp.c index 1511c8b..217a832 100644 --- a/ICL1900/icl1900_lp.c +++ b/ICL1900/icl1900_lp.c @@ -272,7 +272,7 @@ t_stat lpr_svc (UNIT *uptr) char buffer[200]; int i; int len; - int eor; + int eor = 0; /* Handle a disconnect request */ if (uptr->STATUS & DISC) { diff --git a/ICL1900/icl1900_mt.c b/ICL1900/icl1900_mt.c index ed9a2ff..a42fd9a 100644 --- a/ICL1900/icl1900_mt.c +++ b/ICL1900/icl1900_mt.c @@ -319,7 +319,6 @@ t_stat mt_svc (UNIT *uptr) sim_debug(DEBUG_DATA, dptr, "unit=%d write %08o\n", unit, word); /* Put three chars in buffer */ - word = 0; for(i = 16; i >= 0; i-=8) { mt_buffer[uptr->POS++] = (uint8)((word >> i) & 0xff); } @@ -374,6 +373,7 @@ t_stat mt_svc (UNIT *uptr) /* Grab three chars off buffer */ word = 0; + stop = 0; for(i = 0; i <= 16; i+=8) { word |= (uint32)mt_buffer[--uptr->POS] << i; if (uptr->POS == 0) { diff --git a/ICL1900/icl1900_mta.c b/ICL1900/icl1900_mta.c index c2a7491..53b74e9 100644 --- a/ICL1900/icl1900_mta.c +++ b/ICL1900/icl1900_mta.c @@ -357,7 +357,6 @@ t_stat mta_svc (UNIT *uptr) stop = 0; if (uptr->flags & MTUF_9TR) { /* Put three chars in buffer */ - word = 0; uptr->STATUS &= ~CMASK; for(i = 16; i >= 0; i-=8) { mta_buffer[uptr->POS++] = (uint8)((word >> i) & 0xff); @@ -375,7 +374,6 @@ t_stat mta_svc (UNIT *uptr) } } else { /* Put four chars and generate parity */ - word = 0; mode = (uptr->CMD & BCD) ? 0 : 0100; uptr->STATUS &= ~CMASK; for(i = 18; i >= 0; i-=6) { @@ -445,6 +443,8 @@ t_stat mta_svc (UNIT *uptr) uptr->hwmark = reclen; sim_debug(DEBUG_DETAIL, dptr, "Block %d chars\n", reclen); } + + stop = 0; if (uptr->flags & MTUF_9TR) { /* Grab three chars off buffer */ word = 0; @@ -666,7 +666,6 @@ mta_attach(UNIT * uptr, CONST char *file) if ((r = sim_tape_attach_ex(uptr, file, 0, 0)) != SCPE_OK) return r; - uptr->STATUS &= ~OFFLINE; uptr->STATUS = ACCEPT; if (uptr->flags & UNIT_RO) uptr->flags |= MTUF_WLK; diff --git a/ICL1900/icl1900_stdio.c b/ICL1900/icl1900_stdio.c index 285e038..2f42541 100644 --- a/ICL1900/icl1900_stdio.c +++ b/ICL1900/icl1900_stdio.c @@ -470,7 +470,7 @@ chan_output_word(int dev, uint32 *data, int eor) { void chan_set_done(int dev) { - if (dev < 22) + if (dev < 24) SR64 |= B2 >> dev; else SR65 |= ((io_flags & EXT_IO) ? B1 : B2) >> (dev - 24); @@ -478,7 +478,7 @@ chan_set_done(int dev) { void chan_clr_done(int dev) { - if (dev < 22) + if (dev < 24) SR64 &= ~(B2 >> dev); else SR65 &= ~(((io_flags & EXT_IO) ? B1 : B2) >> (dev - 24)); diff --git a/ICL1900/icl1900_sys.c b/ICL1900/icl1900_sys.c index d98133b..8adde14 100755 --- a/ICL1900/icl1900_sys.c +++ b/ICL1900/icl1900_sys.c @@ -285,7 +285,7 @@ sim_load(FILE * fileref, CONST char *cptr, CONST char *fnam, int flag) if ((buffer[j] & 0377) == 0243) image[j] = 024; else - image[j] = ascii_to_mem[buffer[j]]; + image[j] = ascii_to_mem[buffer[j] & 0177]; if (image[j] < 0) { fprintf(stderr, "Char %c: %s\n", buffer[j], buffer); return SCPE_FMT; @@ -312,7 +312,7 @@ sim_load(FILE * fileref, CONST char *cptr, CONST char *fnam, int flag) if ((buffer[j] & 0377) == 0243) image[j] = 024; else - image[j] = ascii_to_mem[buffer[j]]; + image[j] = ascii_to_mem[buffer[j] & 0177]; if (image[j] < 0) { fprintf(stderr, "Char %c: %s", buffer[j], buffer); return SCPE_FMT; @@ -623,9 +623,9 @@ find_opcode(char *op, int *val) if (v > 0177) return -1; } + if (op[i] == 0 && v <= 0177) + return v; } - if (op[i] == 0 && v <= 0177) - return v; for(i = 0; i <= 0177; i++) { if (ops[i].name != '\0' && sim_strcasecmp(op, ops[i].name) == 0) return i; diff --git a/ICL1900/icl1900_tp.c b/ICL1900/icl1900_tp.c index 8a84455..7fcccd5 100644 --- a/ICL1900/icl1900_tp.c +++ b/ICL1900/icl1900_tp.c @@ -33,6 +33,7 @@ #define PP_V_MODE (UNIT_V_UF + 0) #define PP_M_MODE (3 << PP_V_MODE) +#define PP_MODE(x) ((PP_V_MODE & (x)) >> PP_V_MODE) #define UNIT_V_TYPE (UNIT_V_UF + 2) #define UNIT_TYPE (0xf << UNIT_V_TYPE) #define GET_TYPE(x) ((UNIT_TYPE & (x)) >> UNIT_V_TYPE) @@ -123,9 +124,9 @@ UNIT ptp_unit[] = { MTAB ptp_mod[] = { - { PP_M_MODE, PP_MODE_7B, "7b", "7B", NULL }, - { PP_M_MODE, PP_MODE_7P, "7p", "7P", NULL }, - { PP_M_MODE, PP_MODE_7X, "7x", "7X", NULL }, + { PP_M_MODE, PP_MODE_7B << PP_V_MODE, "7b", "7B", NULL }, + { PP_M_MODE, PP_MODE_7P << PP_V_MODE, "7p", "7P", NULL }, + { PP_M_MODE, PP_MODE_7X << PP_V_MODE, "7x", "7X", NULL }, { UNIT_TYPE, SET_TYPE(T1925_1), "1925/1", "1925/1", NULL, NULL, "ICL 1925/1 NSI 300CPM punch."}, { UNIT_TYPE, SET_TYPE(T1925_2), "1925/2", "1925/2", NULL, NULL, "ICL 1922/2 SI 300CPM punch."}, { UNIT_TYPE, SET_TYPE(T1926_1), "1926/1", "1926/1", NULL, NULL, "ICL 1926/1 NSI 1000CPM punch."}, @@ -403,13 +404,13 @@ t_stat ptp_svc (UNIT *uptr) } if (data != 0) { /* Check parity is even */ - if ((uptr->flags & PP_M_MODE) == PP_MODE_7P) { + if (PP_MODE(uptr->flags) == PP_MODE_7P) { data &= 0177; ch = data ^ (data << 4); ch = ch ^ (ch << 2); ch = ch ^ (ch << 1); data |= ch; - } else if ((uptr->flags & PP_M_MODE) == PP_MODE_7X) { + } else if (PP_MODE(uptr->flags) == PP_MODE_7X) { if (data == 044) { data = 0243; } else if (data == 0174) { diff --git a/ICL1900/icl1900_tr.c b/ICL1900/icl1900_tr.c index 6b185c7..a587924 100644 --- a/ICL1900/icl1900_tr.c +++ b/ICL1900/icl1900_tr.c @@ -35,6 +35,7 @@ #define PP_V_MODE (UNIT_V_UF + 0) #define PP_M_MODE (3 << PP_V_MODE) +#define PP_MODE(x) ((PP_M_MODE & (x)) >> PP_V_MODE) #define UNIT_V_TYPE (UNIT_V_UF + 2) #define UNIT_TYPE (0xf << UNIT_V_TYPE) #define GET_TYPE(x) ((UNIT_TYPE & (x)) >> UNIT_V_TYPE) @@ -127,9 +128,9 @@ UNIT ptr_unit[] = { MTAB ptr_mod[] = { - { PP_M_MODE, PP_MODE_7B, "7b", "7B", NULL }, - { PP_M_MODE, PP_MODE_7P, "7p", "7P", NULL }, - { PP_M_MODE, PP_MODE_7X, "7x", "7X", NULL }, + { PP_M_MODE, PP_MODE_7B << PP_V_MODE, "7b", "7B", NULL }, + { PP_M_MODE, PP_MODE_7P << PP_V_MODE, "7p", "7P", NULL }, + { PP_M_MODE, PP_MODE_7X << PP_V_MODE, "7x", "7X", NULL }, { UNIT_TYPE, SET_TYPE(T1915_1), "1915/1", "1915/1", NULL, NULL, "ICL 1915/1 NSI 300CPM reader."}, { UNIT_TYPE, SET_TYPE(T1915_2), "1915/2", "1915/2", NULL, NULL, "ICL 1912/2 SI 300CPM reader."}, { UNIT_TYPE, SET_TYPE(T1916_1), "1916/1", "1916/1", NULL, NULL, "ICL 1916/1 NSI 1000CPM reader."}, @@ -379,14 +380,14 @@ t_stat ptr_svc (UNIT *uptr) sim_debug(DEBUG_DATA, &ptr_dev, "data: %03o\n", data); /* Check parity is even */ - if ((uptr->flags & PP_M_MODE) == PP_MODE_7P) { + if (PP_MODE(uptr->flags) == PP_MODE_7P) { ch = data ^ (data >> 4); ch = ch ^ (ch >> 2); ch = ch ^ (ch >> 1); if (ch != 0) uptr->STATUS = TERMINATE | ERROR; chan_set_done(dev); - } else if ((uptr->flags & PP_M_MODE) == PP_MODE_7X) { + } else if (PP_MODE(uptr->flags) == PP_MODE_7X) { if (data == 0243) { data = 044; } else if (data == 044) { @@ -399,6 +400,7 @@ t_stat ptr_svc (UNIT *uptr) return SCPE_OK; } + ch = 0; if (uptr->CMD & BIN_MODE) { switch (data & 0160) { case 0000: @@ -430,31 +432,40 @@ t_stat ptr_svc (UNIT *uptr) if ((uptr->CMD & STOP_CHAR) != 0 && data == 012) uptr->STATUS |= TERMINATE; shift = DELTA_SHIFT; + ch = (data & 017); break; + case 0040: ch = 020 | (data & 017); break; + case 0060: ch = 000 | (data & 017); break; + case 0140: if ((data & 017) > 013) { shift = DELTA_SHIFT; ch = 070 | (data & 03); break; } + /* Fall Through */ + case 0100: if ((uptr->CMD & 1) == BETA_MODE) shift = ALPHA_SHIFT; uptr->CMD |= ALPHA_MODE; ch = 040 | (data & 037); break; + case 0160: if ((data & 017) > 013) { shift = DELTA_SHIFT; ch = 064 | (data & 03); break; } + /* Fall Through */ + case 0120: if ((uptr->CMD & 1) == ALPHA_MODE) shift = BETA_SHIFT; @@ -466,7 +477,7 @@ t_stat ptr_svc (UNIT *uptr) /* Check if error */ if (shift != 0) { eor = chan_input_char(dev, &shift, 0); - if (eor) { + if (eor && ch != 0) { uptr->STATUS |= TERMINATE; chan_set_done(dev); uptr->CMD &= 1;