Skip to content

Commit 4bd72e6

Browse files
committed
Compiler and static analyzer fixes from Peter Schorn.
1 parent ee3d98a commit 4bd72e6

File tree

8 files changed

+88
-70
lines changed

8 files changed

+88
-70
lines changed

scp.c

Lines changed: 58 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ const struct scp_error {
564564
{"TTMO", "Console Telnet connection timed out"},
565565
{"STALL", "Console Telnet output stall"},
566566
{"AFAIL", "Assertion failed"},
567-
};
567+
};
568568

569569
const size_t size_map[] = { sizeof (int8),
570570
sizeof (int8), sizeof (int16), sizeof (int32), sizeof (int32)
@@ -722,12 +722,12 @@ static CTAB cmd_table[] = {
722722
"sh{ow} fea{tures} show system devices with descriptions\n"
723723
"sh{ow} m{odifiers} show modifiers for all devices\n"
724724
"sh{ow} s{how} show SHOW commands for all devices\n"
725-
"sh{ow} n{ames} show logical names\n"
726-
"sh{ow} q{ueue} show event queue\n"
725+
"sh{ow} n{ames} show logical names\n"
726+
"sh{ow} q{ueue} show event queue\n"
727727
"sh{ow} ti{me} show simulated time\n"
728-
"sh{ow} th{rottle} show simulation rate\n"
728+
"sh{ow} th{rottle} show simulation rate\n"
729729
"sh{ow} a{synch} show asynchronouse I/O state\n"
730-
"sh{ow} ve{rsion} show simulator version\n"
730+
"sh{ow} ve{rsion} show simulator version\n"
731731
"sh{ow} def{ault} show current directory\n"
732732
"sh{ow} <dev> RADIX show device display radix\n"
733733
"sh{ow} <dev> DEBUG show device debug flags\n"
@@ -784,19 +784,19 @@ static CTAB cmd_table[] = {
784784
#if defined(_WIN32) || defined(__hpux)
785785
static
786786
int setenv(const char *envname, const char *envval, int overwrite)
787-
{
788-
char *envstr = malloc(strlen(envname)+strlen(envval)+2);
789-
int r;
787+
{
788+
char *envstr = malloc(strlen(envname)+strlen(envval)+2);
789+
int r;
790790

791-
sprintf(envstr, "%s=%s", envname, envval);
791+
sprintf(envstr, "%s=%s", envname, envval);
792792
#if defined(_WIN32)
793-
r = _putenv(envstr);
794-
free(envstr);
793+
r = _putenv(envstr);
794+
free(envstr);
795795
#else
796-
r = putenv(envstr);
796+
r = putenv(envstr);
797797
#endif
798-
return r;
799-
}
798+
return r;
799+
}
800800
#endif
801801

802802

@@ -1646,7 +1646,6 @@ do {
16461646
cmdp->message ((!echo && !sim_quiet) ? ocptr : NULL, stat);
16471647
else
16481648
if (stat >= SCPE_BASE) { /* report error if not suppressed */
1649-
16501649
printf ("%s\n", sim_error_text (stat));
16511650
if (sim_log)
16521651
fprintf (sim_log, "%s\n", sim_error_text (stat));
@@ -1874,7 +1873,7 @@ return SCPE_OK;
18741873
}
18751874

18761875
/* Assert command
1877-
1876+
18781877
Syntax: ASSERT {<dev>} <reg>{<logical-op><value>}<conditional-op><value>
18791878
18801879
If <dev> is not specified, CPU is assumed. <value> is expressed in the radix
@@ -2196,7 +2195,7 @@ return SCPE_OK;
21962195

21972196
t_stat set_cmd (int32 flag, char *cptr)
21982197
{
2199-
uint32 lvl;
2198+
uint32 lvl = 0;
22002199
t_stat r;
22012200
char gbuf[CBUFSIZE], *cvptr, *svptr;
22022201
DEVICE *dptr;
@@ -2592,7 +2591,7 @@ while (*cptr != 0) { /* do all mods */
25922591
*cvptr++ = 0;
25932592
for (mptr = dptr->modifiers; mptr->mask != 0; mptr++) {
25942593
if (((mptr->mask & MTAB_XTD)? /* right level? */
2595-
(mptr->mask & lvl): (MTAB_VUN & lvl)) &&
2594+
(mptr->mask & lvl): (MTAB_VUN & lvl)) &&
25962595
((mptr->disp && mptr->pstring && /* named disp? */
25972596
(MATCH_CMD (gbuf, mptr->pstring) == 0))
25982597
// ||
@@ -2755,7 +2754,7 @@ if (cptr && (*cptr != 0))
27552754
fprintf (st, "%s simulator V%d.%d-%d", sim_name, vmaj, vmin, vpat);
27562755
if (vdelt)
27572756
fprintf (st, " delta %d", vdelt);
2758-
#if defined(SIM_VERSION_MODE)
2757+
#if defined (SIM_VERSION_MODE)
27592758
fprintf (st, " %s", SIM_VERSION_MODE);
27602759
#endif
27612760
if (flag) {
@@ -2774,13 +2773,25 @@ if (flag) {
27742773
#if defined (SIM_ASYNCH_IO)
27752774
fprintf (st, "\n\t\tAsynchronous I/O support");
27762775
#endif
2777-
#if defined(SIM_ASYNCH_MUX)
2776+
#if defined (SIM_ASYNCH_MUX)
27782777
fprintf (st, "\n\t\tAsynchronous Multiplexer support");
27792778
#endif
2780-
#if defined(SIM_ASYNCH_CLOCKS)
2779+
#if defined (SIM_ASYNCH_CLOCKS)
27812780
fprintf (st, "\n\t\tAsynchronous Clock support");
27822781
#endif
27832782
fprintf (st, "\n\tHost Platform:");
2783+
#if defined (__clang_version__)
2784+
fprintf (st, "\n\t\tCompiler: clang %s", __clang_version__);
2785+
#elif defined (__GNUC__) && defined (__VERSION__)
2786+
fprintf (st, "\n\t\tCompiler: GCC %s", __VERSION__);
2787+
#elif defined (_MSC_FULL_VER) && defined (_MSC_BUILD)
2788+
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);
2789+
#elif defined (__DECC_VER)
2790+
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);
2791+
#endif
2792+
#if defined (__DATE__) && defined (__TIME__)
2793+
fprintf (st, "\n\t\tSimulator Compiled: %s at %s", __DATE__, __TIME__);
2794+
#endif
27842795
fprintf (st, "\n\t\tMemory Access: %s Endian", sim_end ? "Little" : "Big");
27852796
fprintf (st, "\n\t\tMemory Pointer Size: %d bits", (int)sizeof(dptr)*8);
27862797
fprintf (st, "\n\t\t%s", sim_toffset_64 ? "Large File (>2GB) support" : "No Large File support");
@@ -2802,6 +2813,15 @@ if (flag) {
28022813
#define S_xstr(a) S_str(a)
28032814
#define S_str(a) #a
28042815
fprintf (st, "%sgit commit id: %8.8s", flag ? "\n " : " ", S_xstr(SIM_GIT_COMMIT_ID));
2816+
#undef S_str
2817+
#undef S_xstr
2818+
#endif
2819+
#if defined(SIM_BUILD)
2820+
#define S_xstr(a) S_str(a)
2821+
#define S_str(a) #a
2822+
fprintf (st, "%sBuild: %s", flag ? "\n " : " ", S_xstr(SIM_BUILD));
2823+
#undef S_str
2824+
#undef S_xstr
28052825
#endif
28062826
fprintf (st, "\n");
28072827
return SCPE_OK;
@@ -3011,7 +3031,7 @@ DEVICE *dptr;
30113031

30123032
if (cptr && (*cptr != 0)) /* now eol? */
30133033
return SCPE_2MARG;
3014-
for (i = 0; (dptr = sim_devices[i]) != NULL; i++)
3034+
for (i = 0; (dptr = sim_devices[i]) != NULL; i++)
30153035
show_dev_modifiers (st, dptr, NULL, flag, cptr);
30163036
for (i = 0; sim_internal_device_count && (dptr = sim_internal_devices[i]); ++i)
30173037
show_dev_modifiers (st, dptr, NULL, flag, cptr);
@@ -3106,7 +3126,7 @@ sim_trim_endspc(cptr);
31063126
if (chdir(cptr) != 0) {
31073127
printf("Unable to change to: %s\n", cptr);
31083128
return SCPE_IOERR & SCPE_NOMESSAGE;
3109-
}
3129+
}
31103130
return SCPE_OK;
31113131
}
31123132

@@ -3132,7 +3152,7 @@ t_stat r;
31323152
t_addr lo, hi, max = uptr->capac - 1;
31333153
int32 cnt;
31343154

3135-
if (sim_brk_types == 0)
3155+
if (sim_brk_types == 0)
31363156
return SCPE_NOFNC;
31373157
if ((dptr == NULL) || (uptr == NULL))
31383158
return SCPE_IERR;
@@ -3166,7 +3186,7 @@ while (*cptr) {
31663186
sim_brk_showall (st, sim_switches);
31673187
else return SCPE_ARG;
31683188
}
3169-
else {
3189+
else {
31703190
for ( ; lo <= hi; lo = lo + 1) {
31713191
r = ssh_break_one (st, flg, lo, cnt, aptr);
31723192
if (r != SCPE_OK)
@@ -3377,7 +3397,11 @@ if (sim_switches & SWMASK ('R')) { /* read only? */
33773397
else { /* normal */
33783398
uptr->fileref = sim_fopen (cptr, "rb+"); /* open r/w */
33793399
if (uptr->fileref == NULL) { /* open fail? */
3400+
#if defined(EPERM)
3401+
if ((errno == EROFS) || (errno == EACCES) || (errno == EPERM)) {/* read only? */
3402+
#else
33803403
if ((errno == EROFS) || (errno == EACCES)) { /* read only? */
3404+
#endif
33813405
if ((uptr->flags & UNIT_ROABLE) == 0) /* allowed? */
33823406
return attach_err (uptr, SCPE_NORO); /* no error */
33833407
uptr->fileref = sim_fopen (cptr, "rb"); /* open rd only */
@@ -3807,7 +3831,7 @@ fstat (fileno (rfile), &rstat);
38073831
READ_S (buf); /* [V2.5+] read version */
38083832
v35 = v32 = FALSE;
38093833
if (strcmp (buf, save_vercur) == 0) /* version 3.5? */
3810-
v35 = v32 = TRUE;
3834+
v35 = v32 = TRUE;
38113835
else if (strcmp (buf, save_ver32) == 0) /* version 3.2? */
38123836
v32 = TRUE;
38133837
else if (strcmp (buf, save_ver30) != 0) { /* version 3.0? */
@@ -4307,6 +4331,7 @@ return sim_cancel (&sim_step_unit);
43074331
void int_handler (int sig)
43084332
{
43094333
stop_cpu = 1;
4334+
sim_interval = 0; /* should speed up stop detection */
43104335
return;
43114336
}
43124337

@@ -4362,7 +4387,7 @@ for (gptr = gbuf, reason = SCPE_OK;
43624387
tdptr = sim_dfdev; /* working dptr */
43634388
if (strncmp (gptr, "STATE", strlen ("STATE")) == 0) {
43644389
tptr = gptr + strlen ("STATE");
4365-
if (*tptr && (*tptr++ != ','))
4390+
if (*tptr && (*tptr++ != ','))
43664391
return SCPE_ARG;
43674392
if ((lowr = sim_dfdev->registers) == NULL)
43684393
return SCPE_NXREG;
@@ -4421,7 +4446,7 @@ return reason;
44214446
exdep_addr_loop examine/deposit range of addresses
44224447
*/
44234448

4424-
t_stat exdep_reg_loop (FILE *ofile, SCHTAB *schptr, int32 flag, char *cptr,
4449+
t_stat exdep_reg_loop (FILE *ofile, SCHTAB *schptr, int32 flag, char *cptr,
44254450
REG *lowr, REG *highr, uint32 lows, uint32 highs)
44264451
{
44274452
t_stat reason;
@@ -4693,13 +4718,13 @@ if ((rptr->depth > 1) && (rptr->flags & REG_UNIT)) {
46934718
#if defined (USE_INT64)
46944719
if (sz <= sizeof (uint32))
46954720
*((uint32 *) uptr) = (*((uint32 *) uptr) &
4696-
~(((uint32) mask) << rptr->offset)) |
4721+
~(((uint32) mask) << rptr->offset)) |
46974722
(((uint32) val) << rptr->offset);
46984723
else *((t_uint64 *) uptr) = (*((t_uint64 *) uptr)
46994724
& ~(mask << rptr->offset)) | (val << rptr->offset);
47004725
#else
47014726
*((uint32 *) uptr) = (*((uint32 *) uptr) &
4702-
~(((uint32) mask) << rptr->offset)) |
4727+
~(((uint32) mask) << rptr->offset)) |
47034728
(((uint32) val) << rptr->offset);
47044729
#endif
47054730
}
@@ -4887,7 +4912,7 @@ for (i = 0, j = addr; i < count; i++, j = j + dptr->aincr) {
48874912
loc = j / dptr->aincr;
48884913
if (uptr->flags & UNIT_BUF) {
48894914
SZ_STORE (sz, sim_eval[i], uptr->filebuf, loc);
4890-
if (loc >= uptr->hwmark)
4915+
if (loc >= uptr->hwmark)
48914916
uptr->hwmark = (uint32) loc + 1;
48924917
}
48934918
else {
@@ -5526,7 +5551,7 @@ while (*cptr) { /* loop through modifier
55265551
cptr = get_glyph_nc (cptr + 1, gbuf, 0);
55275552
sim_ofile = sim_fopen (gbuf, "a"); /* open for append */
55285553
if (sim_ofile == NULL) { /* open failed? */
5529-
*st = SCPE_OPENERR;
5554+
*st = SCPE_OPENERR;
55305555
return NULL;
55315556
}
55325557
sim_opt_out |= CMD_OPT_OF; /* got output file */
@@ -6565,7 +6590,7 @@ if (sim_deb && (dptr->dctrl & dbits)) {
65656590
Callers should be calling sim_debug() which is a macro
65666591
defined in scp.h which evaluates the action condition before
65676592
incurring call overhead. */
6568-
6593+
65696594
void _sim_debug (uint32 dbits, DEVICE* dptr, const char* fmt, ...)
65706595
{
65716596
if (sim_deb && (dptr->dctrl & dbits)) {

sim_console.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1310,7 +1310,7 @@ if ((std_input) && /* Not Background proces
13101310
GetConsoleMode (std_input, &saved_mode); /* Save Mode */
13111311
return SCPE_OK;
13121312
}
1313-
1313+
13141314
static t_stat sim_os_ttrun (void)
13151315
{
13161316
if ((std_input) && /* If Not Background process? */

sim_defs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ struct sim_schtab {
579579
struct sim_brktab {
580580
t_addr addr; /* address */
581581
int32 typ; /* mask of types */
582-
int32 cnt; /* proceed count */
582+
int32 cnt; /* proceed count */
583583
char *act; /* action string */
584584
};
585585

sim_disk.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ t_stat sim_disk_rdsect (UNIT *uptr, t_lba lba, uint8 *buf, t_seccnt *sectsread,
534534
{
535535
t_stat r;
536536
struct disk_context *ctx = (struct disk_context *)uptr->disk_ctx;
537-
t_seccnt sread;
537+
t_seccnt sread = 0;
538538

539539
sim_debug (ctx->dbit, ctx->dptr, "sim_disk_rdsect(unit=%d, lba=0x%X, sects=%d)\n", (int)(uptr-ctx->dptr->units), lba, sects);
540540

@@ -2185,10 +2185,10 @@ typedef t_int64 int64;
21852185
typedef struct _VHD_Footer {
21862186
/*
21872187
Cookies are used to uniquely identify the original creator of the hard disk
2188-
image. The values are case-sensitive. Microsoft uses the “conectix” string
2188+
image. The values are case-sensitive. Microsoft uses the "conectix" string
21892189
to identify this file as a hard disk image created by Microsoft Virtual
21902190
Server, Virtual PC, and predecessor products. The cookie is stored as an
2191-
eight-character ASCII string with the “c” in the first byte, the “o” in
2191+
eight-character ASCII string with the "c" in the first byte, the "o" in
21922192
the second byte, and so on.
21932193
*/
21942194
char Cookie[8];
@@ -2303,7 +2303,7 @@ typedef struct _VHD_Footer {
23032303
uint32 DiskType;
23042304
/*
23052305
This field holds a basic checksum of the hard disk footer. It is just a
2306-
one’s complement of the sum of all the bytes in the footer without the
2306+
one's complement of the sum of all the bytes in the footer without the
23072307
checksum field.
23082308
If the checksum verification fails, the Virtual PC and Virtual Server
23092309
products will instead use the header. If the checksum in the header also
@@ -2342,7 +2342,7 @@ typedef struct _VHD_Footer {
23422342
} VHD_Footer;
23432343

23442344
/*
2345-
For dynamic and differencing disk images, the “Data Offset” field within
2345+
For dynamic and differencing disk images, the "Data Offset" field within
23462346
the image footer points to a secondary structure that provides additional
23472347
information about the disk image. The dynamic disk header should appear on
23482348
a sector (512-byte) boundary.
@@ -2389,7 +2389,7 @@ typedef struct _VHD_DynamicDiskHeader {
23892389
*/
23902390
uint32 BlockSize;
23912391
/*
2392-
This field holds a basic checksum of the dynamic header. It is a one’s
2392+
This field holds a basic checksum of the dynamic header. It is a one's
23932393
complement of the sum of all the bytes in the header without the checksum
23942394
field.
23952395
If the checksum verification fails the file should be assumed to be corrupt.
@@ -2398,7 +2398,7 @@ typedef struct _VHD_DynamicDiskHeader {
23982398
/*
23992399
This field is used for differencing hard disks. A differencing hard disk
24002400
stores a 128-bit UUID of the parent hard disk. For more information, see
2401-
“Creating Differencing Hard Disk Images” later in this paper.
2401+
"Creating Differencing Hard Disk Images" later in this paper.
24022402
*/
24032403
uint8 ParentUniqueID[16];
24042404
/*
@@ -2424,8 +2424,8 @@ typedef struct _VHD_DynamicDiskHeader {
24242424
/*
24252425
The platform code describes which platform-specific format is used for the
24262426
file locator. For Windows, a file locator is stored as a path (for example.
2427-
“c:\disksimages\ParentDisk.vhd”). On a Macintosh system, the file locator
2428-
is a binary large object (blob) that contains an “alias.” The parent locator
2427+
"c:\disksimages\ParentDisk.vhd"). On a Macintosh system, the file locator
2428+
is a binary large object (blob) that contains an "alias." The parent locator
24292429
table is used to support moving hard disk images across platforms.
24302430
Some current platform codes include the following:
24312431
Platform Code Description

0 commit comments

Comments
 (0)