Compiler and static analyzer fixes from Peter Schorn.

This commit is contained in:
Mark Pizzolato 2013-04-13 16:59:54 -07:00
parent ee3d98a125
commit 4bd72e666c
8 changed files with 88 additions and 70 deletions

57
scp.c
View file

@ -564,7 +564,7 @@ const struct scp_error {
{"TTMO", "Console Telnet connection timed out"}, {"TTMO", "Console Telnet connection timed out"},
{"STALL", "Console Telnet output stall"}, {"STALL", "Console Telnet output stall"},
{"AFAIL", "Assertion failed"}, {"AFAIL", "Assertion failed"},
}; };
const size_t size_map[] = { sizeof (int8), const size_t size_map[] = { sizeof (int8),
sizeof (int8), sizeof (int16), sizeof (int32), sizeof (int32) sizeof (int8), sizeof (int16), sizeof (int32), sizeof (int32)
@ -784,19 +784,19 @@ static CTAB cmd_table[] = {
#if defined(_WIN32) || defined(__hpux) #if defined(_WIN32) || defined(__hpux)
static static
int setenv(const char *envname, const char *envval, int overwrite) int setenv(const char *envname, const char *envval, int overwrite)
{ {
char *envstr = malloc(strlen(envname)+strlen(envval)+2); char *envstr = malloc(strlen(envname)+strlen(envval)+2);
int r; int r;
sprintf(envstr, "%s=%s", envname, envval); sprintf(envstr, "%s=%s", envname, envval);
#if defined(_WIN32) #if defined(_WIN32)
r = _putenv(envstr); r = _putenv(envstr);
free(envstr); free(envstr);
#else #else
r = putenv(envstr); r = putenv(envstr);
#endif #endif
return r; return r;
} }
#endif #endif
@ -1646,7 +1646,6 @@ do {
cmdp->message ((!echo && !sim_quiet) ? ocptr : NULL, stat); cmdp->message ((!echo && !sim_quiet) ? ocptr : NULL, stat);
else else
if (stat >= SCPE_BASE) { /* report error if not suppressed */ if (stat >= SCPE_BASE) { /* report error if not suppressed */
printf ("%s\n", sim_error_text (stat)); printf ("%s\n", sim_error_text (stat));
if (sim_log) if (sim_log)
fprintf (sim_log, "%s\n", sim_error_text (stat)); fprintf (sim_log, "%s\n", sim_error_text (stat));
@ -2196,7 +2195,7 @@ return SCPE_OK;
t_stat set_cmd (int32 flag, char *cptr) t_stat set_cmd (int32 flag, char *cptr)
{ {
uint32 lvl; uint32 lvl = 0;
t_stat r; t_stat r;
char gbuf[CBUFSIZE], *cvptr, *svptr; char gbuf[CBUFSIZE], *cvptr, *svptr;
DEVICE *dptr; DEVICE *dptr;
@ -2755,7 +2754,7 @@ if (cptr && (*cptr != 0))
fprintf (st, "%s simulator V%d.%d-%d", sim_name, vmaj, vmin, vpat); fprintf (st, "%s simulator V%d.%d-%d", sim_name, vmaj, vmin, vpat);
if (vdelt) if (vdelt)
fprintf (st, " delta %d", vdelt); fprintf (st, " delta %d", vdelt);
#if defined(SIM_VERSION_MODE) #if defined (SIM_VERSION_MODE)
fprintf (st, " %s", SIM_VERSION_MODE); fprintf (st, " %s", SIM_VERSION_MODE);
#endif #endif
if (flag) { if (flag) {
@ -2774,13 +2773,25 @@ if (flag) {
#if defined (SIM_ASYNCH_IO) #if defined (SIM_ASYNCH_IO)
fprintf (st, "\n\t\tAsynchronous I/O support"); fprintf (st, "\n\t\tAsynchronous I/O support");
#endif #endif
#if defined(SIM_ASYNCH_MUX) #if defined (SIM_ASYNCH_MUX)
fprintf (st, "\n\t\tAsynchronous Multiplexer support"); fprintf (st, "\n\t\tAsynchronous Multiplexer support");
#endif #endif
#if defined(SIM_ASYNCH_CLOCKS) #if defined (SIM_ASYNCH_CLOCKS)
fprintf (st, "\n\t\tAsynchronous Clock support"); fprintf (st, "\n\t\tAsynchronous Clock support");
#endif #endif
fprintf (st, "\n\tHost Platform:"); fprintf (st, "\n\tHost Platform:");
#if defined (__clang_version__)
fprintf (st, "\n\t\tCompiler: clang %s", __clang_version__);
#elif defined (__GNUC__) && defined (__VERSION__)
fprintf (st, "\n\t\tCompiler: GCC %s", __VERSION__);
#elif defined (_MSC_FULL_VER) && defined (_MSC_BUILD)
fprintf (st, "\n\t\tCompiler: Microsoft Visual C++ %d.%02d.%05d.%02d", _MSC_FULL_VER/10000000, (_MSC_FULL_VER/100000)%100, _MSC_FULL_VER%100000, _MSC_BUILD);
#elif defined (__DECC_VER)
fprintf (st, "\n\t\tCompiler: DEC C %c%d.%d-%03d", ("T SV")[((__DECC_VER/10000)%10)-6], __DECC_VER/10000000, (__DECC_VER/100000)%100, __DECC_VER%10000);
#endif
#if defined (__DATE__) && defined (__TIME__)
fprintf (st, "\n\t\tSimulator Compiled: %s at %s", __DATE__, __TIME__);
#endif
fprintf (st, "\n\t\tMemory Access: %s Endian", sim_end ? "Little" : "Big"); fprintf (st, "\n\t\tMemory Access: %s Endian", sim_end ? "Little" : "Big");
fprintf (st, "\n\t\tMemory Pointer Size: %d bits", (int)sizeof(dptr)*8); fprintf (st, "\n\t\tMemory Pointer Size: %d bits", (int)sizeof(dptr)*8);
fprintf (st, "\n\t\t%s", sim_toffset_64 ? "Large File (>2GB) support" : "No Large File support"); fprintf (st, "\n\t\t%s", sim_toffset_64 ? "Large File (>2GB) support" : "No Large File support");
@ -2802,6 +2813,15 @@ if (flag) {
#define S_xstr(a) S_str(a) #define S_xstr(a) S_str(a)
#define S_str(a) #a #define S_str(a) #a
fprintf (st, "%sgit commit id: %8.8s", flag ? "\n " : " ", S_xstr(SIM_GIT_COMMIT_ID)); fprintf (st, "%sgit commit id: %8.8s", flag ? "\n " : " ", S_xstr(SIM_GIT_COMMIT_ID));
#undef S_str
#undef S_xstr
#endif
#if defined(SIM_BUILD)
#define S_xstr(a) S_str(a)
#define S_str(a) #a
fprintf (st, "%sBuild: %s", flag ? "\n " : " ", S_xstr(SIM_BUILD));
#undef S_str
#undef S_xstr
#endif #endif
fprintf (st, "\n"); fprintf (st, "\n");
return SCPE_OK; return SCPE_OK;
@ -3106,7 +3126,7 @@ sim_trim_endspc(cptr);
if (chdir(cptr) != 0) { if (chdir(cptr) != 0) {
printf("Unable to change to: %s\n", cptr); printf("Unable to change to: %s\n", cptr);
return SCPE_IOERR & SCPE_NOMESSAGE; return SCPE_IOERR & SCPE_NOMESSAGE;
} }
return SCPE_OK; return SCPE_OK;
} }
@ -3377,7 +3397,11 @@ if (sim_switches & SWMASK ('R')) { /* read only? */
else { /* normal */ else { /* normal */
uptr->fileref = sim_fopen (cptr, "rb+"); /* open r/w */ uptr->fileref = sim_fopen (cptr, "rb+"); /* open r/w */
if (uptr->fileref == NULL) { /* open fail? */ if (uptr->fileref == NULL) { /* open fail? */
#if defined(EPERM)
if ((errno == EROFS) || (errno == EACCES) || (errno == EPERM)) {/* read only? */
#else
if ((errno == EROFS) || (errno == EACCES)) { /* read only? */ if ((errno == EROFS) || (errno == EACCES)) { /* read only? */
#endif
if ((uptr->flags & UNIT_ROABLE) == 0) /* allowed? */ if ((uptr->flags & UNIT_ROABLE) == 0) /* allowed? */
return attach_err (uptr, SCPE_NORO); /* no error */ return attach_err (uptr, SCPE_NORO); /* no error */
uptr->fileref = sim_fopen (cptr, "rb"); /* open rd only */ uptr->fileref = sim_fopen (cptr, "rb"); /* open rd only */
@ -4307,6 +4331,7 @@ return sim_cancel (&sim_step_unit);
void int_handler (int sig) void int_handler (int sig)
{ {
stop_cpu = 1; stop_cpu = 1;
sim_interval = 0; /* should speed up stop detection */
return; return;
} }

View file

@ -534,7 +534,7 @@ t_stat sim_disk_rdsect (UNIT *uptr, t_lba lba, uint8 *buf, t_seccnt *sectsread,
{ {
t_stat r; t_stat r;
struct disk_context *ctx = (struct disk_context *)uptr->disk_ctx; struct disk_context *ctx = (struct disk_context *)uptr->disk_ctx;
t_seccnt sread; t_seccnt sread = 0;
sim_debug (ctx->dbit, ctx->dptr, "sim_disk_rdsect(unit=%d, lba=0x%X, sects=%d)\n", (int)(uptr-ctx->dptr->units), lba, sects); sim_debug (ctx->dbit, ctx->dptr, "sim_disk_rdsect(unit=%d, lba=0x%X, sects=%d)\n", (int)(uptr-ctx->dptr->units), lba, sects);
@ -2185,10 +2185,10 @@ typedef t_int64 int64;
typedef struct _VHD_Footer { typedef struct _VHD_Footer {
/* /*
Cookies are used to uniquely identify the original creator of the hard disk Cookies are used to uniquely identify the original creator of the hard disk
image. The values are case-sensitive. Microsoft uses the conectix string image. The values are case-sensitive. Microsoft uses the "conectix" string
to identify this file as a hard disk image created by Microsoft Virtual to identify this file as a hard disk image created by Microsoft Virtual
Server, Virtual PC, and predecessor products. The cookie is stored as an Server, Virtual PC, and predecessor products. The cookie is stored as an
eight-character ASCII string with the c in the first byte, the o in eight-character ASCII string with the "c" in the first byte, the "o" in
the second byte, and so on. the second byte, and so on.
*/ */
char Cookie[8]; char Cookie[8];
@ -2303,7 +2303,7 @@ typedef struct _VHD_Footer {
uint32 DiskType; uint32 DiskType;
/* /*
This field holds a basic checksum of the hard disk footer. It is just a This field holds a basic checksum of the hard disk footer. It is just a
ones complement of the sum of all the bytes in the footer without the one's complement of the sum of all the bytes in the footer without the
checksum field. checksum field.
If the checksum verification fails, the Virtual PC and Virtual Server If the checksum verification fails, the Virtual PC and Virtual Server
products will instead use the header. If the checksum in the header also products will instead use the header. If the checksum in the header also
@ -2342,7 +2342,7 @@ typedef struct _VHD_Footer {
} VHD_Footer; } VHD_Footer;
/* /*
For dynamic and differencing disk images, the Data Offset field within For dynamic and differencing disk images, the "Data Offset" field within
the image footer points to a secondary structure that provides additional the image footer points to a secondary structure that provides additional
information about the disk image. The dynamic disk header should appear on information about the disk image. The dynamic disk header should appear on
a sector (512-byte) boundary. a sector (512-byte) boundary.
@ -2389,7 +2389,7 @@ typedef struct _VHD_DynamicDiskHeader {
*/ */
uint32 BlockSize; uint32 BlockSize;
/* /*
This field holds a basic checksum of the dynamic header. It is a ones This field holds a basic checksum of the dynamic header. It is a one's
complement of the sum of all the bytes in the header without the checksum complement of the sum of all the bytes in the header without the checksum
field. field.
If the checksum verification fails the file should be assumed to be corrupt. If the checksum verification fails the file should be assumed to be corrupt.
@ -2398,7 +2398,7 @@ typedef struct _VHD_DynamicDiskHeader {
/* /*
This field is used for differencing hard disks. A differencing hard disk This field is used for differencing hard disks. A differencing hard disk
stores a 128-bit UUID of the parent hard disk. For more information, see stores a 128-bit UUID of the parent hard disk. For more information, see
Creating Differencing Hard Disk Images later in this paper. "Creating Differencing Hard Disk Images" later in this paper.
*/ */
uint8 ParentUniqueID[16]; uint8 ParentUniqueID[16];
/* /*
@ -2424,8 +2424,8 @@ typedef struct _VHD_DynamicDiskHeader {
/* /*
The platform code describes which platform-specific format is used for the The platform code describes which platform-specific format is used for the
file locator. For Windows, a file locator is stored as a path (for example. file locator. For Windows, a file locator is stored as a path (for example.
c:\disksimages\ParentDisk.vhd). On a Macintosh system, the file locator "c:\disksimages\ParentDisk.vhd"). On a Macintosh system, the file locator
is a binary large object (blob) that contains an alias. The parent locator is a binary large object (blob) that contains an "alias." The parent locator
table is used to support moving hard disk images across platforms. table is used to support moving hard disk images across platforms.
Some current platform codes include the following: Some current platform codes include the following:
Platform Code Description Platform Code Description

View file

@ -2009,41 +2009,41 @@ sim_debug(dev->dbit, dev->dptr, "Determining Address Conflict for MAC address: %
be affected by an address conflict were physically present on a single be affected by an address conflict were physically present on a single
Ethernet cable which might have been extended by a couple of repeaters). Ethernet cable which might have been extended by a couple of repeaters).
Since that time, essentially no networks are single collision domains. Since that time, essentially no networks are single collision domains.
Thick and thinwire Ethernet cables dont exist and very few networks Thick and thinwire Ethernet cables don't exist and very few networks
even have hubs. Today, essentially all LANs are deployed using one even have hubs. Today, essentially all LANs are deployed using one
or more layers of network switches. In a switched LAN environment, the or more layers of network switches. In a switched LAN environment, the
switches on the LAN learn which ports on the LAN source traffic from switches on the LAN "learn" which ports on the LAN source traffic from
which MAC addresses and then forward traffic destined for particular which MAC addresses and then forward traffic destined for particular
MAC address to the appropriate ports. If a particular MAC address is MAC address to the appropriate ports. If a particular MAC address is
already in use somewhere on the LAN, then the switches know where already in use somewhere on the LAN, then the switches "know" where
it is. The host based test using the loopback protocol is poorly it is. The host based test using the loopback protocol is poorly
designed to detect this condition. This test is performed by the host designed to detect this condition. This test is performed by the host
first changing the devices Physical MAC address to the address which first changing the device's Physical MAC address to the address which
is to be tested, and then sending a loopback packet FROM AND TO this is to be tested, and then sending a loopback packet FROM AND TO this
MAC address with a loopback reply to be sent by a system which may be MAC address with a loopback reply to be sent by a system which may be
currently using the MAC address. If no reply is received, then the currently using the MAC address. If no reply is received, then the
MAC address is presumed to be unused. The sending of this packet will MAC address is presumed to be unused. The sending of this packet will
result in its delivery to the right system since the switch port/MAC result in its delivery to the right system since the switch port/MAC
address tables know where to deliver packets destined to this MAC address tables know where to deliver packets destined to this MAC
address, however the response it generates wont be delivered to the address, however the response it generates won't be delivered to the
system performing the test since the switches on the LAN wont know system performing the test since the switches on the LAN won't know
about the local port being the right target for packets with this MAC about the local port being the right target for packets with this MAC
address. A better test design to detect these conflicts would be for address. A better test design to detect these conflicts would be for
the testing system to send a loopback packet FROM the current physical the testing system to send a loopback packet FROM the current physical
MAC address (BEFORE changing it) TO the MAC address being tested with MAC address (BEFORE changing it) TO the MAC address being tested with
the loopback response coming to the current physical MAC address of the loopback response coming to the current physical MAC address of
the device. If a response is received, then the address is in use and the device. If a response is received, then the address is in use and
the attempt to change the devices MAC address should fail. Since we the attempt to change the device's MAC address should fail. Since we
cant change the software running in these simulators to implement this can't change the software running in these simulators to implement this
better conflict detection approach, we can still do the right thing better conflict detection approach, we can still "do the right thing"
in the sim_ether layer. Were already handling the loopback test in the sim_ether layer. We're already handling the loopback test
packets specially since we always had to avoid receiving the packets packets specially since we always had to avoid receiving the packets
which were being sent, but needed to allow for the incoming loopback which were being sent, but needed to allow for the incoming loopback
packets to be properly dealt with. We can extend this current special packets to be properly dealt with. We can extend this current special
handling to change outgoing loopback to self packets to have source handling to change outgoing "loopback to self" packets to have source
AND loopback destination addresses in the packets to be the host NICs AND loopback destination addresses in the packets to be the host NIC's
physical address. The switch network will already know the correct physical address. The switch network will already know the correct
MAC/port relationship for the host NICs physical address, so loopback MAC/port relationship for the host NIC's physical address, so loopback
response packets will be delivered as needed. response packets will be delivered as needed.
Code in _eth_write and _eth_callback provide the special handling to Code in _eth_write and _eth_callback provide the special handling to

View file

@ -78,7 +78,7 @@
#endif #endif
/* cygwin dowsn't have the right features to use the threaded network I/O */ /* cygwin dowsn't have the right features to use the threaded network I/O */
#if defined(__CYGWIN__) #if defined(__CYGWIN__) || defined(__ZAURUS__) // psco added check for Zaurus platform
#define DONT_USE_READER_THREAD #define DONT_USE_READER_THREAD
#endif #endif

View file

@ -180,7 +180,7 @@ return sim_os_msec() - start_time;
const t_bool rtc_avail = TRUE; const t_bool rtc_avail = TRUE;
uint32 sim_os_msec () uint32 sim_os_msec (void)
{ {
uint32 quo, htod, tod[2]; uint32 quo, htod, tod[2];
int32 i; int32 i;
@ -260,7 +260,7 @@ return 0;
const t_bool rtc_avail = TRUE; const t_bool rtc_avail = TRUE;
uint32 sim_os_msec () uint32 sim_os_msec (void)
{ {
if (sim_idle_rate_ms) if (sim_idle_rate_ms)
return timeGetTime (); return timeGetTime ();
@ -330,7 +330,7 @@ return 0;
const t_bool rtc_avail = FALSE; const t_bool rtc_avail = FALSE;
uint32 sim_os_msec () uint32 sim_os_msec (void)
{ {
return 0; return 0;
} }
@ -426,7 +426,7 @@ return 0;
const t_bool rtc_avail = TRUE; const t_bool rtc_avail = TRUE;
uint32 sim_os_msec () uint32 sim_os_msec (void)
{ {
struct timeval cur; struct timeval cur;
struct timezone foo; struct timezone foo;

View file

@ -2561,18 +2561,11 @@ return SCPE_OK;
t_stat tmxr_attach_ex (TMXR *mp, UNIT *uptr, char *cptr, t_bool async) t_stat tmxr_attach_ex (TMXR *mp, UNIT *uptr, char *cptr, t_bool async)
{ {
char* tptr = NULL;
t_stat r; t_stat r;
tptr = (char *) calloc (1, 1);
if (tptr == NULL) /* no more mem? */
return SCPE_MEM;
r = tmxr_open_master (mp, cptr); /* open master socket */ r = tmxr_open_master (mp, cptr); /* open master socket */
if (r != SCPE_OK) { /* error? */ if (r != SCPE_OK) /* error? */
free (tptr); /* release buf */
return r; return r;
}
mp->uptr = uptr; /* save unit for polling */ mp->uptr = uptr; /* save unit for polling */
uptr->filename = _mux_attach_string (uptr->filename, mp);/* save */ uptr->filename = _mux_attach_string (uptr->filename, mp);/* save */
uptr->flags = uptr->flags | UNIT_ATT; /* no more errors */ uptr->flags = uptr->flags | UNIT_ATT; /* no more errors */