AltairZ80: Fix various static source scanning detected issues (Coverity Scan)

This commit is contained in:
Peter Schorn 2017-03-12 12:06:05 +01:00
parent e49f06dcc3
commit 70a8921a7a
7 changed files with 31 additions and 12 deletions

View file

@ -428,10 +428,10 @@ static int32 DAsm(char *S, const uint32 *val, const int32 useZ80Mnemonics, const
R[T1 - T] = '\0'; R[T1 - T] = '\0';
printHex2(H, val[B++]); printHex2(H, val[B++]);
strcat(R, H); strcat(R, H);
strcat(R, T1 + 1); strcat(R, T1 + 1); /* ok, since T1 is a short sub-string coming from one of the tables */
} }
else else
strcpy(R, T); strcpy(R, T); /* ok, since T is a short string coming from one of the tables */
if ( (P = strchr(R, '%')) ) { if ( (P = strchr(R, '%')) ) {
*P = C; *P = C;
if ( (P = strchr(P + 1, '%')) ) if ( (P = strchr(P + 1, '%')) )

View file

@ -137,6 +137,10 @@ static t_stat fw2_attach(UNIT *uptr, CONST char *cptr)
} }
} }
if (i == FW2_MAX_BOARDS) {
return (SCPE_IERR);
}
fw2_info[i] = (FW2_INFO *)calloc(1, sizeof(FW2_INFO)); fw2_info[i] = (FW2_INFO *)calloc(1, sizeof(FW2_INFO));
fw2_info[i]->uptr = uptr; fw2_info[i]->uptr = uptr;
fw2_info[i]->uptr->u3 = baseaddr; fw2_info[i]->uptr->u3 = baseaddr;

View file

@ -781,11 +781,11 @@ uint8 I8272_Write(const uint32 Addr, uint8 cData)
if(i8272_info->fdc_phase == EXEC_PHASE) { if(i8272_info->fdc_phase == EXEC_PHASE) {
switch(i8272_info->cmd[0] & 0x1F) { switch(i8272_info->cmd[0] & 0x1F) {
case I8272_READ_TRACK: case I8272_READ_TRACK: /* intentional fallthrough */
sim_printf("I8272: " ADDRESS_FORMAT " Read a track (untested.)" NLP, PCX); sim_printf("I8272: " ADDRESS_FORMAT " Read a track (untested.)" NLP, PCX);
i8272_info->fdc_sector = 1; /* Read entire track from sector 1...eot */ i8272_info->fdc_sector = 1; /* Read entire track from sector 1...eot */
case I8272_READ_DATA: case I8272_READ_DATA: /* intentional fallthrough */
case I8272_READ_DELETED_DATA: case I8272_READ_DELETED_DATA: /* intentional fallthrough */
disk_read = 1; disk_read = 1;
case I8272_WRITE_DATA: case I8272_WRITE_DATA:
case I8272_WRITE_DELETED_DATA: case I8272_WRITE_DELETED_DATA:

View file

@ -3288,7 +3288,7 @@ unsigned int m68k_is_valid_instruction(unsigned int instruction, unsigned int cp
if(g_instruction_table[instruction] == d68010_moves_32) if(g_instruction_table[instruction] == d68010_moves_32)
return 0; return 0;
if(g_instruction_table[instruction] == d68010_rtd) if(g_instruction_table[instruction] == d68010_rtd)
return 0; return 0; /* intentional fallthrough, older models have more invalid instructions */
case M68K_CPU_TYPE_68010: case M68K_CPU_TYPE_68010:
if(g_instruction_table[instruction] == d68020_bcc_32) if(g_instruction_table[instruction] == d68020_bcc_32)
return 0; return 0;

View file

@ -1993,6 +1993,7 @@ static opcode_handler_struct m68k_opcode_handler_table[] =
void m68ki_build_opcode_table(void) void m68ki_build_opcode_table(void)
{ {
opcode_handler_struct *ostruct; opcode_handler_struct *ostruct;
int cycle_cost;
int instr; int instr;
int i; int i;
int j; int j;
@ -2040,8 +2041,17 @@ void m68ki_build_opcode_table(void)
m68ki_instruction_jump_table[instr] = ostruct->opcode_handler; m68ki_instruction_jump_table[instr] = ostruct->opcode_handler;
for(k=0;k<NUM_CPU_TYPES;k++) for(k=0;k<NUM_CPU_TYPES;k++)
m68ki_cycles[k][instr] = ostruct->cycles[k]; m68ki_cycles[k][instr] = ostruct->cycles[k];
// For all shift operations with known shift distance (encoded in instruction word), this is backported from MUSASHI Version 3.4
if((instr & 0xf000) == 0xe000 && (!(instr & 0x20))) if((instr & 0xf000) == 0xe000 && (!(instr & 0x20)))
m68ki_cycles[0][instr] = m68ki_cycles[1][instr] = ostruct->cycles[k] + ((((j-1)&7)+1)<<1); {
// On the 68000 and 68010 shift distance affect execution time.
// Add the cycle cost of shifting; 2 times the shift distance
cycle_cost = ((((i-1)&7)+1)<<1);
m68ki_cycles[0][instr] += cycle_cost;
m68ki_cycles[1][instr] += cycle_cost;
// On the 68020 shift distance does not affect execution time
m68ki_cycles[2][instr] += 0;
}
} }
} }
ostruct++; ostruct++;

View file

@ -255,6 +255,9 @@ static t_stat mfdc_attach(UNIT *uptr, CONST char *cptr)
} }
i = find_unit_index(uptr); i = find_unit_index(uptr);
if (i == -1) {
return (SCPE_IERR);
}
/* Default for new file is DSK */ /* Default for new file is DSK */
uptr->u3 = IMAGE_TYPE_DSK; uptr->u3 = IMAGE_TYPE_DSK;
@ -474,8 +477,7 @@ static uint8 MFDC_Read(const uint32 Addr)
case IMAGE_TYPE_DSK: case IMAGE_TYPE_DSK:
if(pDrive->uptr->fileref == NULL) { if(pDrive->uptr->fileref == NULL) {
sim_printf(".fileref is NULL!" NLP); sim_printf(".fileref is NULL!" NLP);
} else { } else if (sim_fseek((pDrive->uptr)->fileref, sec_offset, SEEK_SET) == 0) {
sim_fseek((pDrive->uptr)->fileref, sec_offset, SEEK_SET);
#ifdef USE_VGI #ifdef USE_VGI
rtn = sim_fread(sdata.raw, 1, MFDC_SECTOR_LEN, (pDrive->uptr)->fileref); rtn = sim_fread(sdata.raw, 1, MFDC_SECTOR_LEN, (pDrive->uptr)->fileref);
if (rtn != MFDC_SECTOR_LEN) if (rtn != MFDC_SECTOR_LEN)
@ -484,6 +486,8 @@ static uint8 MFDC_Read(const uint32 Addr)
if (rtn != 256) if (rtn != 256)
#endif /* USE_VGI */ #endif /* USE_VGI */
sim_printf("%s: sim_fread error. Result = %d." NLP, __FUNCTION__, rtn); sim_printf("%s: sim_fread error. Result = %d." NLP, __FUNCTION__, rtn);
} else {
sim_printf("%s: sim_fseek error." NLP, __FUNCTION__);
} }
break; break;
case IMAGE_TYPE_CPT: case IMAGE_TYPE_CPT:
@ -601,13 +605,14 @@ static uint8 MFDC_Write(const uint32 Addr, uint8 cData)
case IMAGE_TYPE_DSK: case IMAGE_TYPE_DSK:
if(pDrive->uptr->fileref == NULL) { if(pDrive->uptr->fileref == NULL) {
sim_printf(".fileref is NULL!" NLP); sim_printf(".fileref is NULL!" NLP);
} else { } else if (sim_fseek((pDrive->uptr)->fileref, sec_offset, SEEK_SET) == 0) {
sim_fseek((pDrive->uptr)->fileref, sec_offset, SEEK_SET);
#ifdef USE_VGI #ifdef USE_VGI
sim_fwrite(sdata.raw, 1, MFDC_SECTOR_LEN, (pDrive->uptr)->fileref); sim_fwrite(sdata.raw, 1, MFDC_SECTOR_LEN, (pDrive->uptr)->fileref);
#else #else
sim_fwrite(sdata.u.data, 1, 256, (pDrive->uptr)->fileref); sim_fwrite(sdata.u.data, 1, 256, (pDrive->uptr)->fileref);
#endif /* USE_VGI */ #endif /* USE_VGI */
} else {
sim_printf("%s: sim_fseek error." NLP, __FUNCTION__);
} }
break; break;
case IMAGE_TYPE_CPT: case IMAGE_TYPE_CPT:

View file

@ -260,7 +260,7 @@ typedef struct extop { /* extended operand */
#define MAXPREFIX 4 #define MAXPREFIX 4
typedef struct { /* an instruction itself */ typedef struct { /* an instruction itself */
char *label; /* the label defined, or NULL */ /* char *label; not needed */ /* the label defined, or NULL */
int prefixes[MAXPREFIX]; /* instruction prefixes, if any */ int prefixes[MAXPREFIX]; /* instruction prefixes, if any */
int nprefix; /* number of entries in above */ int nprefix; /* number of entries in above */
int opcode; /* the opcode - not just the string */ int opcode; /* the opcode - not just the string */