From 7bdb5aee8d740521a0c321d73a50aa6bb7e96642 Mon Sep 17 00:00:00 2001 From: Mark Pizzolato Date: Mon, 19 Oct 2020 12:30:43 -0700 Subject: [PATCH] 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 --- Ibm1130/ibm1130_cpu.c | 2 +- Ibm1130/ibm1130_cr.c | 10 +++++----- Ibm1130/ibm1130_fmt.c | 13 +++++++------ 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/Ibm1130/ibm1130_cpu.c b/Ibm1130/ibm1130_cpu.c index 67b7af21..21a7ff6f 100644 --- a/Ibm1130/ibm1130_cpu.c +++ b/Ibm1130/ibm1130_cpu.c @@ -495,7 +495,7 @@ static int32 ibm1130_qcount () 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; char msg[50]; int cwincount = 0, status; diff --git a/Ibm1130/ibm1130_cr.c b/Ibm1130/ibm1130_cr.c index 42ba3550..fe96be21 100644 --- a/Ibm1130/ibm1130_cr.c +++ b/Ibm1130/ibm1130_cr.c @@ -1565,12 +1565,12 @@ static t_stat cr_attach (UNIT *uptr, CONST char *iptr) { t_stat rval; t_bool use_decklist, old_quiet; - char gbuf[4*CBUFSIZE], *cptr = gbuf; + char gbuf[4*CBUFSIZE], *cptr = gbuf; char *c, *arg, quote; gbuf[sizeof(gbuf)-1] = '\0'; - strncpy(gbuf, iptr, sizeof(gbuf)-1); - cr_detach(uptr); /* detach file and possibly deck file */ + strlcpy(gbuf, iptr, sizeof gbuf); + cr_detach(uptr); /* detach file and possibly deck file */ 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 */ 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 */ @@ -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 */ 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? */ uptr->filename = (char *)calloc(CBUFSIZE, sizeof(char)); strcpy(uptr->filename, "(stdin)"); diff --git a/Ibm1130/ibm1130_fmt.c b/Ibm1130/ibm1130_fmt.c index f18d6df5..305eab8b 100644 --- a/Ibm1130/ibm1130_fmt.c +++ b/Ibm1130/ibm1130_fmt.c @@ -63,6 +63,7 @@ #include #include #include "ibm1130_fmt.h" +#include "sim_defs.h" #define MAXLINE 81 /* maximum output line size */ #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 */ 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 */ return p_szOut; /* .. return token pointer */ @@ -179,15 +180,15 @@ size_t iI; /* work integer */ if (*p_pszEdit == '*') /* q. comment line? */ { /* 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 */ 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 */ - 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 */ { @@ -248,7 +249,7 @@ int bContinue; /* true if continue 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 */ { @@ -313,7 +314,7 @@ char pszWork[WORKSZ]; /* work buffer */ } 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 */ {