mirror of
https://github.com/simh/simh.git
synced 2026-02-15 20:27:40 +00:00
SCP: Coverity warning cleanup from Dave Bryan
This commit is contained in:
committed by
Mark Pizzolato
parent
d739fe435e
commit
0b4ecef91c
@@ -23,6 +23,7 @@
|
|||||||
used in advertising or otherwise to promote the sale, use or other dealings
|
used in advertising or otherwise to promote the sale, use or other dealings
|
||||||
in this Software without prior written authorization from Robert M Supnik.
|
in this Software without prior written authorization from Robert M Supnik.
|
||||||
|
|
||||||
|
27-Dec-18 JDB Added missing fall through comment in ControlHandler
|
||||||
18-Mar-18 RMS Fixed deboff not to close stdout or stderr (Dave Bryan)
|
18-Mar-18 RMS Fixed deboff not to close stdout or stderr (Dave Bryan)
|
||||||
31-Mar-15 RMS Backported parity feature from GitHub master
|
31-Mar-15 RMS Backported parity feature from GitHub master
|
||||||
10-Nov-14 JDB Added -N option to SET CONSOLE LOG and SET CONSOLE DEBUG
|
10-Nov-14 JDB Added -N option to SET CONSOLE LOG and SET CONSOLE DEBUG
|
||||||
@@ -770,6 +771,8 @@ ControlHandler(DWORD dwCtrlType)
|
|||||||
case CTRL_LOGOFF_EVENT: // User is logging off
|
case CTRL_LOGOFF_EVENT: // User is logging off
|
||||||
if (!GetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), &Mode))
|
if (!GetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), &Mode))
|
||||||
return TRUE; // Not our User, so ignore
|
return TRUE; // Not our User, so ignore
|
||||||
|
/* fall through into simulation termination */
|
||||||
|
|
||||||
case CTRL_SHUTDOWN_EVENT: // System is shutting down
|
case CTRL_SHUTDOWN_EVENT: // System is shutting down
|
||||||
int_handler(0);
|
int_handler(0);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|||||||
50
sim_fio.c
50
sim_fio.c
@@ -1,6 +1,6 @@
|
|||||||
/* sim_fio.c: simulator file I/O library
|
/* sim_fio.c: simulator file I/O library
|
||||||
|
|
||||||
Copyright (c) 1993-2015, Robert M Supnik
|
Copyright (c) 1993-2018, Robert M Supnik
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a
|
Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
copy of this software and associated documentation files (the "Software"),
|
copy of this software and associated documentation files (the "Software"),
|
||||||
@@ -23,6 +23,7 @@
|
|||||||
used in advertising or otherwise to promote the sale, use or other dealings
|
used in advertising or otherwise to promote the sale, use or other dealings
|
||||||
in this Software without prior written authorization from Robert M Supnik.
|
in this Software without prior written authorization from Robert M Supnik.
|
||||||
|
|
||||||
|
28-Dec-18 JDB Modify sim_fseeko, sim_ftell for mingwrt 5.2 compatibility
|
||||||
02-Apr-15 RMS Backported from GitHub master
|
02-Apr-15 RMS Backported from GitHub master
|
||||||
28-Jun-07 RMS Added VMS IA64 support (from Norm Lastovica)
|
28-Jun-07 RMS Added VMS IA64 support (from Norm Lastovica)
|
||||||
10-Jul-06 RMS Fixed linux conditionalization (from Chaskiel Grundman)
|
10-Jul-06 RMS Fixed linux conditionalization (from Chaskiel Grundman)
|
||||||
@@ -233,42 +234,29 @@ return (t_offset)(ftell (st));
|
|||||||
#define S_SIM_IO_FSEEK_EXT_ 1
|
#define S_SIM_IO_FSEEK_EXT_ 1
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
|
/* [JDB] The previous Win32 versions of sim_fseeko and sim_ftell attempted to
|
||||||
|
use fsetpos and fgetpos by manipulating an fpos_t value as though it were a
|
||||||
|
64-bit integer. This worked with version 5.0 of the mingw runtime library,
|
||||||
|
which declared an fpos_t to be a long long int. With version 5.2, fpos_t is
|
||||||
|
now a union containing a long long int, so that it cannot be manipulated.
|
||||||
|
The manipulation was always suspect, as the MSVC++ 2008 documentation says,
|
||||||
|
"The [fpos_t] value is stored in an internal format and is intended for use
|
||||||
|
only by fgetpos and fsetpos." It worked, but only because VC++ declared it
|
||||||
|
as an __int64 value. If that changes, the original code would break, as it
|
||||||
|
now does for mingw.
|
||||||
|
|
||||||
|
Therefore, we now simply call _fseeki64 and _ftelli64, which are provided by
|
||||||
|
both mingw and VC++ and work as expected without manipulation.
|
||||||
|
*/
|
||||||
|
|
||||||
int sim_fseeko (FILE *st, t_offset offset, int whence)
|
int sim_fseeko (FILE *st, t_offset offset, int whence)
|
||||||
{
|
{
|
||||||
fpos_t fileaddr;
|
return _fseeki64 (st, offset, whence);
|
||||||
struct _stati64 statb;
|
|
||||||
|
|
||||||
switch (whence) {
|
|
||||||
|
|
||||||
case SEEK_SET:
|
|
||||||
fileaddr = (fpos_t)offset;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SEEK_END:
|
|
||||||
if (_fstati64 (_fileno (st), &statb))
|
|
||||||
return (-1);
|
|
||||||
fileaddr = statb.st_size + offset;
|
|
||||||
break;
|
|
||||||
case SEEK_CUR:
|
|
||||||
if (fgetpos (st, &fileaddr))
|
|
||||||
return (-1);
|
|
||||||
fileaddr = fileaddr + offset;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
errno = EINVAL;
|
|
||||||
return (-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
return fsetpos (st, &fileaddr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
t_offset sim_ftell (FILE *st)
|
t_offset sim_ftell (FILE *st)
|
||||||
{
|
{
|
||||||
fpos_t fileaddr;
|
return (t_offset) _ftelli64 (st);
|
||||||
if (fgetpos (st, &fileaddr))
|
|
||||||
return (-1);
|
|
||||||
return (t_offset)fileaddr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* end Windows */
|
#endif /* end Windows */
|
||||||
|
|||||||
87
sim_tape.c
87
sim_tape.c
@@ -1,6 +1,6 @@
|
|||||||
/* sim_tape.c: simulator tape support library
|
/* sim_tape.c: simulator tape support library
|
||||||
|
|
||||||
Copyright (c) 1993-2017, Robert M Supnik
|
Copyright (c) 1993-2018, Robert M Supnik
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a
|
Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
copy of this software and associated documentation files (the "Software"),
|
copy of this software and associated documentation files (the "Software"),
|
||||||
@@ -26,6 +26,7 @@
|
|||||||
Ultimately, this will be a place to hide processing of various tape formats,
|
Ultimately, this will be a place to hide processing of various tape formats,
|
||||||
as well as OS-specific direct hardware access.
|
as well as OS-specific direct hardware access.
|
||||||
|
|
||||||
|
27-Dec-18 JDB Added missing fall through comment in sim_tape_wrrecf
|
||||||
03-May-17 JDB Added support for erasing tape marks to sim_tape_errec[fr]
|
03-May-17 JDB Added support for erasing tape marks to sim_tape_errec[fr]
|
||||||
02-May-17 JDB Added error checks to sim_fseek calls
|
02-May-17 JDB Added error checks to sim_fseek calls
|
||||||
18-Jul-16 JDB Added sim_tape_errecf, sim_tape_errecr functions
|
18-Jul-16 JDB Added sim_tape_errecf, sim_tape_errecr functions
|
||||||
@@ -109,13 +110,10 @@ static const uint32 bpi [] = { /* tape density table, i
|
|||||||
|
|
||||||
#define BPI_COUNT (sizeof (bpi) / sizeof (bpi [0])) /* count of density table entries */
|
#define BPI_COUNT (sizeof (bpi) / sizeof (bpi [0])) /* count of density table entries */
|
||||||
|
|
||||||
extern int32 sim_switches;
|
static t_stat sim_tape_ioerr (UNIT *uptr);
|
||||||
|
static t_stat sim_tape_wrdata (UNIT *uptr, uint32 dat);
|
||||||
t_stat sim_tape_ioerr (UNIT *uptr);
|
static uint32 sim_tape_tpc_map (UNIT *uptr, t_addr *map);
|
||||||
t_stat sim_tape_wrdata (UNIT *uptr, uint32 dat);
|
static t_addr sim_tape_tpc_fnd (UNIT *uptr, t_addr *map);
|
||||||
uint32 sim_tape_tpc_map (UNIT *uptr, t_addr *map);
|
|
||||||
t_addr sim_tape_tpc_fnd (UNIT *uptr, t_addr *map);
|
|
||||||
|
|
||||||
static t_stat tape_erase_fwd (UNIT *uptr, t_mtrlnt gap_size);
|
static t_stat tape_erase_fwd (UNIT *uptr, t_mtrlnt gap_size);
|
||||||
static t_stat tape_erase_rev (UNIT *uptr, t_mtrlnt gap_size);
|
static t_stat tape_erase_rev (UNIT *uptr, t_mtrlnt gap_size);
|
||||||
|
|
||||||
@@ -290,7 +288,7 @@ t_tpclnt tpcbc;
|
|||||||
t_mtrlnt buffer [256]; /* local tape buffer */
|
t_mtrlnt buffer [256]; /* local tape buffer */
|
||||||
uint32 bufcntr, bufcap; /* buffer counter and capacity */
|
uint32 bufcntr, bufcap; /* buffer counter and capacity */
|
||||||
int32 runaway_counter, sizeof_gap; /* bytes remaining before runaway and bytes per gap */
|
int32 runaway_counter, sizeof_gap; /* bytes remaining before runaway and bytes per gap */
|
||||||
t_stat status = SCPE_OK;
|
t_stat status = MTSE_OK;
|
||||||
|
|
||||||
MT_CLR_PNU (uptr); /* clear the position-not-updated flag */
|
MT_CLR_PNU (uptr); /* clear the position-not-updated flag */
|
||||||
|
|
||||||
@@ -463,7 +461,7 @@ else switch (f) { /* otherwise the read me
|
|||||||
all_eof = 0;
|
all_eof = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (status == SCPE_OK) {
|
if (status == MTSE_OK) {
|
||||||
*bc = sbc; /* save rec lnt */
|
*bc = sbc; /* save rec lnt */
|
||||||
sim_fseek (uptr->fileref, uptr->pos, SEEK_SET); /* for read */
|
sim_fseek (uptr->fileref, uptr->pos, SEEK_SET); /* for read */
|
||||||
uptr->pos = uptr->pos + sbc; /* spc over record */
|
uptr->pos = uptr->pos + sbc; /* spc over record */
|
||||||
@@ -515,7 +513,6 @@ return status;
|
|||||||
|
|
||||||
2. See the notes at "sim_tape_rdlntf" and "tape_erase_fwd" regarding tape
|
2. See the notes at "sim_tape_rdlntf" and "tape_erase_fwd" regarding tape
|
||||||
runaway and the erase gap implementation, respectively.
|
runaway and the erase gap implementation, respectively.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static t_stat sim_tape_rdlntr (UNIT *uptr, t_mtrlnt *bc)
|
static t_stat sim_tape_rdlntr (UNIT *uptr, t_mtrlnt *bc)
|
||||||
@@ -529,7 +526,7 @@ t_tpclnt tpcbc;
|
|||||||
t_mtrlnt buffer [256]; /* local tape buffer */
|
t_mtrlnt buffer [256]; /* local tape buffer */
|
||||||
uint32 bufcntr, bufcap; /* buffer counter and capacity */
|
uint32 bufcntr, bufcap; /* buffer counter and capacity */
|
||||||
int32 runaway_counter, sizeof_gap; /* bytes remaining before runaway and bytes per gap */
|
int32 runaway_counter, sizeof_gap; /* bytes remaining before runaway and bytes per gap */
|
||||||
t_stat status = SCPE_OK;
|
t_stat status = MTSE_OK;
|
||||||
|
|
||||||
MT_CLR_PNU (uptr); /* clear the position-not-updated flag */
|
MT_CLR_PNU (uptr); /* clear the position-not-updated flag */
|
||||||
|
|
||||||
@@ -671,7 +668,7 @@ else switch (f) { /* otherwise the read me
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (status == SCPE_OK) {
|
if (status == MTSE_OK) {
|
||||||
uptr->pos = uptr->pos - sbc; /* update position */
|
uptr->pos = uptr->pos - sbc; /* update position */
|
||||||
*bc = sbc; /* save rec lnt */
|
*bc = sbc; /* save rec lnt */
|
||||||
sim_fseek (uptr->fileref, uptr->pos, SEEK_SET); /* for read */
|
sim_fseek (uptr->fileref, uptr->pos, SEEK_SET); /* for read */
|
||||||
@@ -716,7 +713,8 @@ t_addr opos;
|
|||||||
t_stat st;
|
t_stat st;
|
||||||
|
|
||||||
opos = uptr->pos; /* old position */
|
opos = uptr->pos; /* old position */
|
||||||
if (st = sim_tape_rdlntf (uptr, &tbc)) /* read rec lnt */
|
st = sim_tape_rdlntf (uptr, &tbc); /* read rec lnt */
|
||||||
|
if (st != MTSE_OK)
|
||||||
return st;
|
return st;
|
||||||
*bc = rbc = MTR_L (tbc); /* strip error flag */
|
*bc = rbc = MTR_L (tbc); /* strip error flag */
|
||||||
if (rbc > max) { /* rec out of range? */
|
if (rbc > max) { /* rec out of range? */
|
||||||
@@ -724,7 +722,7 @@ if (rbc > max) { /* rec out of range? */
|
|||||||
uptr->pos = opos;
|
uptr->pos = opos;
|
||||||
return MTSE_INVRL;
|
return MTSE_INVRL;
|
||||||
}
|
}
|
||||||
i = sim_fread (buf, sizeof (uint8), rbc, uptr->fileref);/* read record */
|
i = (t_mtrlnt) sim_fread (buf, sizeof (uint8), rbc, uptr->fileref); /* read record */
|
||||||
if (ferror (uptr->fileref)) { /* error? */
|
if (ferror (uptr->fileref)) { /* error? */
|
||||||
MT_SET_PNU (uptr);
|
MT_SET_PNU (uptr);
|
||||||
uptr->pos = opos;
|
uptr->pos = opos;
|
||||||
@@ -765,12 +763,13 @@ uint32 f = MT_GET_FMT (uptr);
|
|||||||
t_mtrlnt i, rbc, tbc;
|
t_mtrlnt i, rbc, tbc;
|
||||||
t_stat st;
|
t_stat st;
|
||||||
|
|
||||||
if (st = sim_tape_rdlntr (uptr, &tbc)) /* read rec lnt */
|
st = sim_tape_rdlntr (uptr, &tbc); /* read rec lnt */
|
||||||
|
if (st != MTSE_OK)
|
||||||
return st;
|
return st;
|
||||||
*bc = rbc = MTR_L (tbc); /* strip error flag */
|
*bc = rbc = MTR_L (tbc); /* strip error flag */
|
||||||
if (rbc > max) /* rec out of range? */
|
if (rbc > max) /* rec out of range? */
|
||||||
return MTSE_INVRL;
|
return MTSE_INVRL;
|
||||||
i = sim_fread (buf, sizeof (uint8), rbc, uptr->fileref);/* read record */
|
i = (t_mtrlnt) sim_fread (buf, sizeof (uint8), rbc, uptr->fileref); /* read record */
|
||||||
if (ferror (uptr->fileref)) /* error? */
|
if (ferror (uptr->fileref)) /* error? */
|
||||||
return sim_tape_ioerr (uptr);
|
return sim_tape_ioerr (uptr);
|
||||||
for ( ; i < rbc; i++) /* fill with 0's */
|
for ( ; i < rbc; i++) /* fill with 0's */
|
||||||
@@ -815,6 +814,9 @@ switch (f) { /* case on format */
|
|||||||
|
|
||||||
case MTUF_F_STD: /* standard */
|
case MTUF_F_STD: /* standard */
|
||||||
sbc = MTR_L ((bc + 1) & ~1); /* pad odd length */
|
sbc = MTR_L ((bc + 1) & ~1); /* pad odd length */
|
||||||
|
|
||||||
|
/* fall through into the E11 handler */
|
||||||
|
|
||||||
case MTUF_F_E11: /* E11 */
|
case MTUF_F_E11: /* E11 */
|
||||||
sim_fwrite (&bc, sizeof (t_mtrlnt), 1, uptr->fileref);
|
sim_fwrite (&bc, sizeof (t_mtrlnt), 1, uptr->fileref);
|
||||||
sim_fwrite (buf, sizeof (uint8), sbc, uptr->fileref);
|
sim_fwrite (buf, sizeof (uint8), sbc, uptr->fileref);
|
||||||
@@ -843,7 +845,7 @@ return MTSE_OK;
|
|||||||
|
|
||||||
/* Write metadata forward (internal routine) */
|
/* Write metadata forward (internal routine) */
|
||||||
|
|
||||||
t_stat sim_tape_wrdata (UNIT *uptr, uint32 dat)
|
static t_stat sim_tape_wrdata (UNIT *uptr, uint32 dat)
|
||||||
{
|
{
|
||||||
MT_CLR_PNU (uptr);
|
MT_CLR_PNU (uptr);
|
||||||
if ((uptr->flags & UNIT_ATT) == 0) /* not attached? */
|
if ((uptr->flags & UNIT_ATT) == 0) /* not attached? */
|
||||||
@@ -1360,7 +1362,23 @@ else /* otherwise */
|
|||||||
return tape_erase_rev (uptr, gap_size); /* erase the requested gap */
|
return tape_erase_rev (uptr, gap_size); /* erase the requested gap */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Space record forward */
|
/* Space record forward
|
||||||
|
|
||||||
|
Inputs:
|
||||||
|
uptr = pointer to tape unit
|
||||||
|
bc = pointer to size of record skipped
|
||||||
|
Outputs:
|
||||||
|
status = operation status
|
||||||
|
|
||||||
|
exit condition position
|
||||||
|
|
||||||
|
unit unattached unchanged
|
||||||
|
read error unchanged, PNU set
|
||||||
|
end of file/medium unchanged, PNU set
|
||||||
|
tape mark updated
|
||||||
|
data record updated
|
||||||
|
data record error updated
|
||||||
|
*/
|
||||||
|
|
||||||
t_stat sim_tape_sprecf (UNIT *uptr, t_mtrlnt *bc)
|
t_stat sim_tape_sprecf (UNIT *uptr, t_mtrlnt *bc)
|
||||||
{
|
{
|
||||||
@@ -1371,7 +1389,24 @@ st = sim_tape_rdlntf (uptr, bc); /* get record length */
|
|||||||
return st;
|
return st;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Space record reverse */
|
/* Space record reverse
|
||||||
|
|
||||||
|
Inputs:
|
||||||
|
uptr = pointer to tape unit
|
||||||
|
bc = pointer to size of records skipped
|
||||||
|
Outputs:
|
||||||
|
status = operation status
|
||||||
|
|
||||||
|
exit condition position
|
||||||
|
|
||||||
|
unit unattached unchanged
|
||||||
|
beginning of tape unchanged
|
||||||
|
read error unchanged
|
||||||
|
end of file unchanged
|
||||||
|
end of medium updated
|
||||||
|
tape mark updated
|
||||||
|
data record updated
|
||||||
|
*/
|
||||||
|
|
||||||
t_stat sim_tape_sprecr (UNIT *uptr, t_mtrlnt *bc)
|
t_stat sim_tape_sprecr (UNIT *uptr, t_mtrlnt *bc)
|
||||||
{
|
{
|
||||||
@@ -1424,12 +1459,12 @@ return (uptr->capac && (uptr->pos >= uptr->capac))? TRUE: FALSE;
|
|||||||
|
|
||||||
t_bool sim_tape_wrp (UNIT *uptr)
|
t_bool sim_tape_wrp (UNIT *uptr)
|
||||||
{
|
{
|
||||||
return (uptr->flags & MTUF_WRP)? TRUE: FALSE;
|
return ((uptr->flags & MTUF_WRP) || (MT_GET_FMT (uptr) == MTUF_F_TPC))? TRUE: FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Process I/O error */
|
/* Process I/O error */
|
||||||
|
|
||||||
t_stat sim_tape_ioerr (UNIT *uptr)
|
static t_stat sim_tape_ioerr (UNIT *uptr)
|
||||||
{
|
{
|
||||||
perror ("Magtape library I/O error");
|
perror ("Magtape library I/O error");
|
||||||
clearerr (uptr->fileref);
|
clearerr (uptr->fileref);
|
||||||
@@ -1442,10 +1477,10 @@ t_stat sim_tape_set_fmt (UNIT *uptr, int32 val, char *cptr, void *desc)
|
|||||||
{
|
{
|
||||||
uint32 f;
|
uint32 f;
|
||||||
|
|
||||||
if (uptr->flags & UNIT_ATT)
|
|
||||||
return SCPE_ALATT;
|
|
||||||
if (uptr == NULL)
|
if (uptr == NULL)
|
||||||
return SCPE_IERR;
|
return SCPE_IERR;
|
||||||
|
if (uptr->flags & UNIT_ATT)
|
||||||
|
return SCPE_ALATT;
|
||||||
if (cptr == NULL)
|
if (cptr == NULL)
|
||||||
return SCPE_ARG;
|
return SCPE_ARG;
|
||||||
for (f = 0; f < MTUF_N_FMT; f++) {
|
for (f = 0; f < MTUF_N_FMT; f++) {
|
||||||
@@ -1472,7 +1507,7 @@ return SCPE_OK;
|
|||||||
|
|
||||||
/* Map a TPC format tape image */
|
/* Map a TPC format tape image */
|
||||||
|
|
||||||
uint32 sim_tape_tpc_map (UNIT *uptr, t_addr *map)
|
static uint32 sim_tape_tpc_map (UNIT *uptr, t_addr *map)
|
||||||
{
|
{
|
||||||
t_addr tpos;
|
t_addr tpos;
|
||||||
t_tpclnt bc;
|
t_tpclnt bc;
|
||||||
@@ -1496,7 +1531,7 @@ return objc;
|
|||||||
|
|
||||||
/* Find the preceding record in a TPC file */
|
/* Find the preceding record in a TPC file */
|
||||||
|
|
||||||
t_addr sim_tape_tpc_fnd (UNIT *uptr, t_addr *map)
|
static t_addr sim_tape_tpc_fnd (UNIT *uptr, t_addr *map)
|
||||||
{
|
{
|
||||||
uint32 lo, hi, p;
|
uint32 lo, hi, p;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user