SCP: Coverity warning cleanup

This commit is contained in:
Mark Pizzolato 2017-03-28 22:35:26 -07:00
parent 8d8a286c58
commit cb6b0a526a

19
scp.c
View file

@ -2906,7 +2906,8 @@ for (nargs = 0; nargs < 10; ) { /* extract arguments */
if (do_arg [0] == NULL) /* need at least 1 */ if (do_arg [0] == NULL) /* need at least 1 */
return SCPE_2FARG; return SCPE_2FARG;
if ((fpin = fopen (do_arg[0], "r")) == NULL) { /* file failed to open? */ if ((fpin = fopen (do_arg[0], "r")) == NULL) { /* file failed to open? */
sim_strlcat (strcpy (cbuf, do_arg[0]), ".sim", sizeof(cbuf));/* try again with .sim extension */ sim_strlcpy (cbuf, do_arg[0], sizeof (cbuf)); /* try again with .sim extension */
sim_strlcat (cbuf, ".sim", sizeof (cbuf));
if ((fpin = fopen (cbuf, "r")) == NULL) { /* failed a second time? */ if ((fpin = fopen (cbuf, "r")) == NULL) { /* failed a second time? */
if (flag == 0) /* cmd line file? */ if (flag == 0) /* cmd line file? */
fprintf (stderr, "Can't open file %s\n", do_arg[0]); fprintf (stderr, "Can't open file %s\n", do_arg[0]);
@ -3739,10 +3740,11 @@ int32 saved_goto_line = sim_goto_line[sim_do_depth];
if (NULL == sim_gotofile) return SCPE_UNK; /* only valid inside of do_cmd */ if (NULL == sim_gotofile) return SCPE_UNK; /* only valid inside of do_cmd */
get_glyph (fcptr, gbuf1, 0); get_glyph (fcptr, gbuf1, 0);
if ('\0' == gbuf1[0]) return SCPE_ARG; /* unspecified goto target */ if ('\0' == gbuf1[0]) /* unspecified goto target */
return sim_messagef (SCPE_ARG, "Missing goto target\n");
fpos = ftell(sim_gotofile); /* Save start position */ fpos = ftell(sim_gotofile); /* Save start position */
if (fpos < 0) if (fpos < 0)
return SCPE_IERR; return sim_messagef (SCPE_IERR, "goto ftell error: %s\n", strerror (errno));
rewind(sim_gotofile); /* start search for label */ rewind(sim_gotofile); /* start search for label */
sim_goto_line[sim_do_depth] = 0; /* reset line number */ sim_goto_line[sim_do_depth] = 0; /* reset line number */
sim_do_echo = 0; /* Don't echo while searching for label */ sim_do_echo = 0; /* Don't echo while searching for label */
@ -3754,7 +3756,7 @@ while (1) {
if (*cptr != ':') continue; /* ignore non-labels */ if (*cptr != ':') continue; /* ignore non-labels */
++cptr; /* skip : */ ++cptr; /* skip : */
while (sim_isspace (*cptr)) ++cptr; /* skip blanks */ while (sim_isspace (*cptr)) ++cptr; /* skip blanks */
cptr = get_glyph (cptr, gbuf, 0); /* get label glyph */ get_glyph (cptr, gbuf, 0); /* get label glyph */
if (0 == strcmp(gbuf, gbuf1)) { if (0 == strcmp(gbuf, gbuf1)) {
sim_brk_clract (); /* goto defangs current actions */ sim_brk_clract (); /* goto defangs current actions */
sim_do_echo = saved_do_echo; /* restore echo mode */ sim_do_echo = saved_do_echo; /* restore echo mode */
@ -3764,10 +3766,10 @@ while (1) {
} }
} }
sim_do_echo = saved_do_echo; /* restore echo mode */ sim_do_echo = saved_do_echo; /* restore echo mode */
if (fseek(sim_gotofile, fpos, SEEK_SET)) /* restore start position */
return SCPE_IERR;
sim_goto_line[sim_do_depth] = saved_goto_line; /* restore start line number */ sim_goto_line[sim_do_depth] = saved_goto_line; /* restore start line number */
return SCPE_ARG; if (fseek(sim_gotofile, fpos, SEEK_SET)) /* restore start position */
return sim_messagef (SCPE_IERR, "goto seek error: %s\n", strerror (errno));
return sim_messagef (SCPE_ARG, "goto target '%s' not found\n", gbuf1);
} }
/* Return command */ /* Return command */
@ -5152,7 +5154,8 @@ if (dir) {
sprintf (FileName, "%s/%s", DirName, ent->d_name); sprintf (FileName, "%s/%s", DirName, ent->d_name);
#endif #endif
p_name = FileName + strlen (DirName); p_name = FileName + strlen (DirName);
stat (FileName, &filestat); memset (&filestat, 0, sizeof (filestat));
(void)stat (FileName, &filestat);
FileSize = (t_offset)((filestat.st_mode & S_IFDIR) ? 0 : sim_fsize_name_ex (FileName)); FileSize = (t_offset)((filestat.st_mode & S_IFDIR) ? 0 : sim_fsize_name_ex (FileName));
entry (DirName, p_name, FileSize, &filestat, context); entry (DirName, p_name, FileSize, &filestat, context);
} }