IBM1130: Compiler warning cleanup

- Initialize local state variable to 0.  Likely non functional changes due
  to lack of depth in static analysis scan.  Coverity detects real problems
  like this.
- Migrate use of strncpy to strlcpy to assure safe buffer operations
This commit is contained in:
Mark Pizzolato 2020-10-19 12:30:43 -07:00
parent 65d7868148
commit 7bdb5aee8d
3 changed files with 13 additions and 12 deletions

View file

@ -495,7 +495,7 @@ static int32 ibm1130_qcount ()
t_stat sim_instr (void) t_stat sim_instr (void)
{ {
int32 i, eaddr, INDIR, IR, F, DSPLC, word2, oldval, newval, src, src2, dst, abit, xbit; int32 i, eaddr, INDIR, IR, F, DSPLC, word2 = 0, oldval, newval, src, src2, dst, abit, xbit;
int32 iocc_addr, iocc_op, iocc_dev, iocc_func, iocc_mod, result; int32 iocc_addr, iocc_op, iocc_dev, iocc_func, iocc_mod, result;
char msg[50]; char msg[50];
int cwincount = 0, status; int cwincount = 0, status;

View file

@ -1565,12 +1565,12 @@ static t_stat cr_attach (UNIT *uptr, CONST char *iptr)
{ {
t_stat rval; t_stat rval;
t_bool use_decklist, old_quiet; t_bool use_decklist, old_quiet;
char gbuf[4*CBUFSIZE], *cptr = gbuf; char gbuf[4*CBUFSIZE], *cptr = gbuf;
char *c, *arg, quote; char *c, *arg, quote;
gbuf[sizeof(gbuf)-1] = '\0'; gbuf[sizeof(gbuf)-1] = '\0';
strncpy(gbuf, iptr, sizeof(gbuf)-1); strlcpy(gbuf, iptr, sizeof gbuf);
cr_detach(uptr); /* detach file and possibly deck file */ cr_detach(uptr); /* detach file and possibly deck file */
CLRBIT(uptr->flags, UNIT_SCRATCH|UNIT_QUIET|UNIT_DEBUG|UNIT_PHYSICAL|UNIT_LOWERCASE); /* set options */ CLRBIT(uptr->flags, UNIT_SCRATCH|UNIT_QUIET|UNIT_DEBUG|UNIT_PHYSICAL|UNIT_LOWERCASE); /* set options */
@ -1620,7 +1620,7 @@ static t_stat cr_attach (UNIT *uptr, CONST char *iptr)
*c++ = 0; /* term arg at space or closing quote */ *c++ = 0; /* term arg at space or closing quote */
list_arg[list_nargs] = list_save[list_nargs]; /* set pointer to permanent storage location */ list_arg[list_nargs] = list_save[list_nargs]; /* set pointer to permanent storage location */
strncpy(list_arg[list_nargs], arg, MAXARGLEN); /* store copy */ strlcpy(list_arg[list_nargs], arg, sizeof list_arg[list_nargs]); /* store copy */
} }
list_arg[list_nargs] = NULL; /* NULL terminate the end of the argument list */ list_arg[list_nargs] = NULL; /* NULL terminate the end of the argument list */
@ -1643,7 +1643,7 @@ static t_stat cr_attach (UNIT *uptr, CONST char *iptr)
if (list_nargs > 1 && ! use_decklist) /* if not using deck file, there should have been only one name */ if (list_nargs > 1 && ! use_decklist) /* if not using deck file, there should have been only one name */
return SCPE_2MARG; return SCPE_2MARG;
if (strcmp(cptr, "(stdin)") == 0 && ! use_decklist) { /* standard input */ if (strcmp(cptr, "(stdin)") == 0 && ! use_decklist) { /* standard input */
if (uptr->flags & UNIT_DIS) return SCPE_UDIS; /* disabled? */ if (uptr->flags & UNIT_DIS) return SCPE_UDIS; /* disabled? */
uptr->filename = (char *)calloc(CBUFSIZE, sizeof(char)); uptr->filename = (char *)calloc(CBUFSIZE, sizeof(char));
strcpy(uptr->filename, "(stdin)"); strcpy(uptr->filename, "(stdin)");

View file

@ -63,6 +63,7 @@
#include <ctype.h> #include <ctype.h>
#include <string.h> #include <string.h>
#include "ibm1130_fmt.h" #include "ibm1130_fmt.h"
#include "sim_defs.h"
#define MAXLINE 81 /* maximum output line size */ #define MAXLINE 81 /* maximum output line size */
#define WORKSZ 256 /* size for tab work area */ #define WORKSZ 256 /* size for tab work area */
@ -154,7 +155,7 @@ char* pszX; /* work pointer */
memset(p_szOut, 0, p_iLen); /* zero out output area */ memset(p_szOut, 0, p_iLen); /* zero out output area */
if (iI > 0) /* q. any chars? */ if (iI > 0) /* q. any chars? */
strncpy(p_szOut, *p_pszToken, MIN(iI, p_iLen-1)); /* a. yes.. copy max of p_iLen-1 */ memcpy(p_szOut, *p_pszToken, MIN(iI, p_iLen-1)); /* a. yes.. copy max of p_iLen-1 */
*p_pszToken += iI; /* point beyond token */ *p_pszToken += iI; /* point beyond token */
return p_szOut; /* .. return token pointer */ return p_szOut; /* .. return token pointer */
@ -179,15 +180,15 @@ size_t iI; /* work integer */
if (*p_pszEdit == '*') /* q. comment line? */ if (*p_pszEdit == '*') /* q. comment line? */
{ /* a. yes.. */ { /* a. yes.. */
strncpy(pszWork, EditToWhitespace(p_pszEdit, width), MAXLINE); /* .. convert any tabs */ strlcpy(pszWork, EditToWhitespace(p_pszEdit, width), sizeof pszWork);/* .. convert any tabs */
sprintf(gszOutput, ACOMMENTFMT, pszWork); /* .. put the comment out there in the opcode column */ sprintf(gszOutput, ACOMMENTFMT, pszWork); /* .. put the comment out there in the opcode column */
return gszOutput; /* .. and return it */ return gszOutput; /* .. and return it */
} }
strncpy(pszLine, p_pszEdit, MAXLINE-1); /* copy the line local */ strlcpy(pszLine, p_pszEdit, sizeof pszLine); /* copy the line local */
ExpandTabs(pszLine, pszWork, gaiAsmTabs); /* expand the tabs */ ExpandTabs(pszLine, pszWork, gaiAsmTabs); /* expand the tabs */
strncpy(pszLine, pszWork, MAXLINE-1); /* copy the line back */ strlcpy(pszLine, pszWork, sizeof pszLine); /* copy the line back */
for (iI = strlen(pszLine); iI--;) /* trim trailing whitespace */ for (iI = strlen(pszLine); iI--;) /* trim trailing whitespace */
{ {
@ -248,7 +249,7 @@ int bContinue; /* true if continue
return EditToWhitespace(p_pszEdit, width); return EditToWhitespace(p_pszEdit, width);
} }
strncpy(pszLine, p_pszEdit, MAXLINE-1); /* copy the line local */ strlcpy(pszLine, p_pszEdit, sizeof pszLine); /* copy the line local */
for (iI = strlen(pszLine); iI--;) /* trim trailing whitespace */ for (iI = strlen(pszLine); iI--;) /* trim trailing whitespace */
{ {
@ -313,7 +314,7 @@ char pszWork[WORKSZ]; /* work buffer */
} }
ExpandTabs(pszLine, pszWork, gaiPlainTabs); /* expand the tabs */ ExpandTabs(pszLine, pszWork, gaiPlainTabs); /* expand the tabs */
strncpy(gszOutput, pszWork, MAXLINE-1); /* copy the line back */ strlcpy(gszOutput, pszWork, sizeof gszOutput); /* copy the line back */
for (iI = strlen(gszOutput); iI--;) /* look at each character */ for (iI = strlen(gszOutput); iI--;) /* look at each character */
{ {