SCP: Cleanup gcc compiler flagged potential issues

Compiler warnings about undeclared case fall throughs, and potential
buffer overruns,
This commit is contained in:
Mark Pizzolato 2019-01-21 16:43:17 -08:00
parent 3cca0cf90b
commit cb9876ce65
5 changed files with 17 additions and 10 deletions

3
scp.c
View file

@ -13062,10 +13062,9 @@ for (hblock = astrings; (htext = *hblock) != NULL; hblock++) {
} }
break; break;
case 'D': case 'D':
if (dptr) { if (dptr)
appendText (topic, dptr->name, strlen (dptr->name)); appendText (topic, dptr->name, strlen (dptr->name));
break; break;
}
case 'S': case 'S':
appendText (topic, sim_name, strlen (sim_name)); appendText (topic, sim_name, strlen (sim_name));
break; break;

View file

@ -1570,6 +1570,7 @@ for (i=(was_active_command ? sim_rem_cmd_active_line : 0);
case '\n': case '\n':
if (rem->buf_ptr == 0) if (rem->buf_ptr == 0)
break; break;
/* fall through */
case '\r': case '\r':
tmxr_linemsg (lp, "\r\n"); tmxr_linemsg (lp, "\r\n");
if (rem->buf_ptr+1 >= rem->buf_size) { if (rem->buf_ptr+1 >= rem->buf_size) {
@ -2580,7 +2581,8 @@ while (*cptr != 0) { /* do all mods */
if (serport != INVALID_HANDLE) { if (serport != INVALID_HANDLE) {
sim_close_serial (serport); sim_close_serial (serport);
if (r == SCPE_OK) { if (r == SCPE_OK) {
char cbuf[CBUFSIZE]; char cbuf[CBUFSIZE+10];
if ((sim_con_tmxr.master) || /* already open? */ if ((sim_con_tmxr.master) || /* already open? */
(sim_con_ldsc.serport)) (sim_con_ldsc.serport))
sim_set_noserial (0, NULL); /* close first */ sim_set_noserial (0, NULL); /* close first */
@ -2662,7 +2664,7 @@ else {
if (!*pref) if (!*pref)
return SCPE_MEM; return SCPE_MEM;
get_glyph_nc (filename, gbuf, 0); /* reparse */ get_glyph_nc (filename, gbuf, 0); /* reparse */
strncpy ((*pref)->name, gbuf, sizeof((*pref)->name)-1); strlcpy ((*pref)->name, gbuf, sizeof((*pref)->name));
if (sim_switches & SWMASK ('N')) /* if a new log file is requested */ if (sim_switches & SWMASK ('N')) /* if a new log file is requested */
*pf = sim_fopen (gbuf, (binary ? "w+b" : "w+"));/* then open an empty file */ *pf = sim_fopen (gbuf, (binary ? "w+b" : "w+"));/* then open an empty file */
else /* otherwise */ else /* otherwise */
@ -3388,6 +3390,7 @@ ControlHandler(DWORD dwCtrlType)
case CTRL_LOGOFF_EVENT: // User is logging off case CTRL_LOGOFF_EVENT: // User is logging off
if (!GetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), &Mode)) if (!GetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), &Mode))
return TRUE; // Not our User, so ignore return TRUE; // Not our User, so ignore
/* fall through */
case CTRL_SHUTDOWN_EVENT: // System is shutting down case CTRL_SHUTDOWN_EVENT: // System is shutting down
int_handler(0); int_handler(0);
return TRUE; return TRUE;

View file

@ -3464,15 +3464,16 @@ if ((sDynamic) &&
else else
ParentName[i/2] = Pdata[i] ? Pdata[i] : Pdata[i+1]; ParentName[i/2] = Pdata[i] ? Pdata[i] : Pdata[i+1];
free (Pdata); free (Pdata);
memset (CheckPath, 0, sizeof (CheckPath));
if (0 == memcmp (sDynamic->ParentLocatorEntries[j].PlatformCode, "W2ku", 4)) if (0 == memcmp (sDynamic->ParentLocatorEntries[j].PlatformCode, "W2ku", 4))
strncpy (CheckPath, ParentName, sizeof (CheckPath)-1); strlcpy (CheckPath, ParentName, sizeof (CheckPath));
else else
if (0 == memcmp (sDynamic->ParentLocatorEntries[j].PlatformCode, "W2ru", 4)) { if (0 == memcmp (sDynamic->ParentLocatorEntries[j].PlatformCode, "W2ru", 4)) {
const char *c; const char *c;
if ((c = strrchr (szVHDPath, '\\'))) { if ((c = strrchr (szVHDPath, '\\'))) {
memcpy (CheckPath, szVHDPath, c-szVHDPath+1); memcpy (CheckPath, szVHDPath, c-szVHDPath+1);
strncpy (CheckPath+strlen(CheckPath), ParentName, sizeof (CheckPath)-(strlen (CheckPath)+1)); strlcat (CheckPath, ParentName, sizeof (CheckPath));
} }
} }
VhdPathToHostPath (CheckPath, CheckPath, sizeof (CheckPath)); VhdPathToHostPath (CheckPath, CheckPath, sizeof (CheckPath));

View file

@ -889,7 +889,8 @@ if ((hFind = FindFirstFileA (cptr, &File)) != INVALID_HANDLE_VALUE) {
sprintf (&DirName[strlen (DirName)], "%c", *pathsep); sprintf (&DirName[strlen (DirName)], "%c", *pathsep);
do { do {
FileSize = (((t_int64)(File.nFileSizeHigh)) << 32) | File.nFileSizeLow; FileSize = (((t_int64)(File.nFileSizeHigh)) << 32) | File.nFileSizeLow;
sprintf (FileName, "%s%s", DirName, File.cFileName); strlcpy (FileName, DirName, sizeof (FileName));
strlcat (FileName, File.cFileName, sizeof (FileName));
stat (FileName, &filestat); stat (FileName, &filestat);
entry (DirName, File.cFileName, FileSize, &filestat, context); entry (DirName, File.cFileName, FileSize, &filestat, context);
} while (FindNextFile (hFind, &File)); } while (FindNextFile (hFind, &File));

View file

@ -517,10 +517,10 @@ memset (lp->rbr, 0, lp->rxbsz); /* clear break status ar
static void tmxr_report_connection (TMXR *mp, TMLN *lp) static void tmxr_report_connection (TMXR *mp, TMLN *lp)
{ {
int32 unwritten, psave; int32 unwritten, psave;
char cmsg[80]; char cmsg[160];
char dmsg[80] = ""; char dmsg[80] = "";
char lmsg[80] = ""; char lmsg[80] = "";
char msgbuf[256] = ""; char msgbuf[512] = "";
if ((!lp->notelnet) || (sim_switches & SWMASK ('V'))) { if ((!lp->notelnet) || (sim_switches & SWMASK ('V'))) {
sprintf (cmsg, "\n\r\nConnected to the %s simulator ", sim_name); sprintf (cmsg, "\n\r\nConnected to the %s simulator ", sim_name);
@ -2024,6 +2024,7 @@ for (i = 0; i < mp->lines; i++) { /* loop thru lines */
lp->telnet_sent_opts[tmp] |= TNOS_DONT;/* Record DONT sent */ lp->telnet_sent_opts[tmp] |= TNOS_DONT;/* Record DONT sent */
} }
} }
/* fall through */
case TNS_WONT: /* IAC+WILL/WONT prev */ case TNS_WONT: /* IAC+WILL/WONT prev */
if (tmp == TN_BIN) { /* BIN? */ if (tmp == TN_BIN) { /* BIN? */
if (lp->tsta == TNS_WILL) { if (lp->tsta == TNS_WILL) {
@ -2103,6 +2104,7 @@ for (i = 0; i < mp->lines; i++) { /* loop thru lines */
lp->telnet_sent_opts[tmp] |= TNOS_WONT;/* Record WONT sent */ lp->telnet_sent_opts[tmp] |= TNOS_WONT;/* Record WONT sent */
} }
} }
/* fall through */
case TNS_SKIP: default: /* skip char */ case TNS_SKIP: default: /* skip char */
tmxr_rmvrc (lp, j); /* remove char */ tmxr_rmvrc (lp, j); /* remove char */
lp->tsta = TNS_NORM; /* next normal */ lp->tsta = TNS_NORM; /* next normal */
@ -5389,6 +5391,7 @@ if ((dptr) && (dbits & dptr->dctrl)) {
i += (tmxr_buf_debug_telnet_options ((u_char *)(&buf[i]), bufsize-i) - 1); i += (tmxr_buf_debug_telnet_options ((u_char *)(&buf[i]), bufsize-i) - 1);
break; break;
} }
/* fall through */
default: default:
if (isprint((u_char)buf[i])) if (isprint((u_char)buf[i]))
tmxr_buf_debug_char (buf[i]); tmxr_buf_debug_char (buf[i]);