From 0f72a160fee2f7d8cbb4cef43b57d103f8a4238e Mon Sep 17 00:00:00 2001 From: Seth Morabito Date: Sun, 20 Oct 2019 13:27:16 -0700 Subject: [PATCH] 3b2: Fix coverity issues --- 3B2/3b2_ctc.c | 24 +++++++++++++----------- 3B2/3b2_mau.h | 1 + 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/3B2/3b2_ctc.c b/3B2/3b2_ctc.c index 0d76d383..6af8c7d4 100644 --- a/3B2/3b2_ctc.c +++ b/3B2/3b2_ctc.c @@ -264,7 +264,7 @@ static void ctc_cmd(uint8 cid, uint32 vtoc_addr, pdinfo_addr, ctjob_addr; uint32 maxpass, blkno, delay, last_byte; uint8 dev, c; - uint8 sec_buf[512]; + uint8 sec_buf[VTOC_SECSZ]; int32 b, i, j; int32 block_count, read_bytes, remainder, dest; t_seccnt secrw = 0; @@ -497,11 +497,11 @@ static void ctc_cmd(uint8 cid, blkno = ATOW(rapp_data, 0); - for (b = 0; b < rqe->byte_count / 512; b++) { + for (b = 0; b < rqe->byte_count / VTOC_SECSZ; b++) { ctc_state[dev].time += 10; - for (j = 0; j < 512; j++) { + for (j = 0; j < VTOC_SECSZ; j++) { /* Fill the buffer */ - sec_buf[j] = pread_b(rqe->address + (b * 512) + j); + sec_buf[j] = pread_b(rqe->address + (b * VTOC_SECSZ) + j); } lba = blkno + b; result = sim_disk_wrsect(&ctc_unit, lba, sec_buf, &secrw, 1); @@ -559,13 +559,13 @@ static void ctc_cmd(uint8 cid, * to be read, and use that to figure out how many bytes will * be left over to read from an "extra" block */ last_byte = ctc_state[dev].bytnum + rqe->byte_count; - remainder = last_byte % 512; + remainder = last_byte % VTOC_SECSZ; /* The number of blocks we have to read in total is computed * by looking at the byte count, PLUS any remainder that will * be left after crossing a block boundary */ - block_count = rqe->byte_count / 512; - if (((rqe->byte_count % 512) > 0 || remainder > 0)) { + block_count = rqe->byte_count / VTOC_SECSZ; + if (((rqe->byte_count % VTOC_SECSZ) > 0 || remainder > 0)) { block_count++; } @@ -575,7 +575,7 @@ static void ctc_cmd(uint8 cid, uint32 start_byte; /* Add some read time to the read time counter */ ctc_state[dev].time += 10; - start_byte = ctc_state[dev].bytnum % 512; + start_byte = ctc_state[dev].bytnum % VTOC_SECSZ; lba = blkno + b; result = sim_disk_rdsect(&ctc_unit, lba, sec_buf, &secrw, 1); if (result == SCPE_OK) { @@ -585,12 +585,14 @@ static void ctc_cmd(uint8 cid, if (b == (block_count - 1) && remainder > 0) { read_bytes = remainder; } else { - read_bytes = 512 - start_byte; + read_bytes = VTOC_SECSZ - start_byte; } for (j = 0; j < read_bytes; j++) { uint32 offset; /* Drain the buffer */ - if (b == 0 && start_byte != 0) { + if (b == 0 && + start_byte > 0 && + (j + start_byte) < VTOC_SECSZ) { /* This is a partial read of the first block, * continuing to read from a previous partial * block read. */ @@ -783,7 +785,7 @@ t_stat ctc_svc(UNIT *uptr) t_stat ctc_attach(UNIT *uptr, CONST char *cptr) { - return sim_disk_attach(uptr, cptr, 512, 1, TRUE, 0, "CIPHER23", 0, 0); + return sim_disk_attach(uptr, cptr, VTOC_SECSZ, 1, TRUE, 0, "CIPHER23", 0, 0); } t_stat ctc_detach(UNIT *uptr) diff --git a/3B2/3b2_mau.h b/3B2/3b2_mau.h index e71b92ac..197c9bb7 100644 --- a/3B2/3b2_mau.h +++ b/3B2/3b2_mau.h @@ -215,6 +215,7 @@ #define PACK_XFP(SIGN,EXP,FRAC,V) do { \ (V)->frac = (FRAC); \ (V)->sign_exp = ((uint16)(SIGN) << 15) + (EXP); \ + (V)->s = FALSE; \ } while (0) #define PACK_XFP_S(SIGN,EXP,FRAC,S,V) do { \