From 62dc8ff6ec367145ea4c5aa66ab00f15aa42851f Mon Sep 17 00:00:00 2001 From: Mark Pizzolato Date: Wed, 29 Mar 2017 07:04:29 -0700 Subject: [PATCH] ALTAIR: Fix potential reference to uninitialized memory (Coverity) --- ALTAIR/altair_sys.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/ALTAIR/altair_sys.c b/ALTAIR/altair_sys.c index 83093ba0..f3b2d471 100644 --- a/ALTAIR/altair_sys.c +++ b/ALTAIR/altair_sys.c @@ -234,6 +234,7 @@ t_stat parse_sym (CONST char *cptr, t_addr addr, UNIT *uptr, t_value *val, int32 int32 cflag, i = 0, j, r; char gbuf[CBUFSIZE]; +memset (gbuf, 0, sizeof (gbuf)); cflag = (uptr == NULL) || (uptr == &cpu_unit); while (isspace (*cptr)) cptr++; /* absorb spaces */ if ((sw & SWMASK ('A')) || ((*cptr == '\'') && cptr++)) { /* ASCII char? */ @@ -251,7 +252,7 @@ if ((sw & SWMASK ('C')) || ((*cptr == '"') && cptr++)) { /* ASCII string? */ or numeric (including spaces). */ -while (1) { +while (i < sizeof (gbuf)) { if (*cptr == ',' || *cptr == '\0' || isdigit(*cptr)) break; @@ -285,9 +286,7 @@ if (toupper(gbuf[0]) == 'M' && /* kill trailing spaces if any */ gbuf[i] = '\0'; -for (j = i - 1; gbuf[j] == ' '; j--) { - gbuf[j] = '\0'; -} +sim_trim_endspc (gbuf); /* find opcode in table */ for (j = 0; j < 256; j++) {