Skip to content

Commit 95f1e9f

Browse files
committed
SCP: cppcheck suggestions
1 parent 2c658df commit 95f1e9f

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

scp.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4617,10 +4617,14 @@ int i;
46174617
const char *ap;
46184618
const char *fixup_needed = strchr (gbuf, ':');
46194619
char *tgbuf = NULL;
4620-
size_t tgbuf_size = MAX(rbuf_size, 1 + (size_t)(fixup_needed - gbuf));
4621-
4622-
if (fixup_needed) {
4623-
tgbuf = (char *)calloc (tgbuf_size, 1);
4620+
/* If fixup_needed == NULL, fixup - gbuf will end up being a VERY large number, so
4621+
* default to a reasonable size. */
4622+
size_t tgbuf_size = rbuf_size;
4623+
4624+
if (fixup_needed != NULL) {
4625+
tgbuf_size = 1 + (size_t) (fixup_needed - gbuf);
4626+
tgbuf = (char *) calloc (tgbuf_size, 1);
4627+
tgbuf[fixup_needed - gbuf] = '\0';
46244628
memcpy (tgbuf, gbuf, (fixup_needed - gbuf));
46254629
gbuf = tgbuf;
46264630
}
@@ -11236,7 +11240,7 @@ CONST char *get_sim_sw (CONST char *cptr)
1123611240
int32 lsw, lnum;
1123711241
char gbuf[CBUFSIZE];
1123811242

11239-
while (*cptr == '-') { /* while switches */
11243+
while (cptr != NULL && *cptr == '-') { /* while switches */
1124011244
cptr = get_glyph (cptr, gbuf, 0); /* get switch glyph */
1124111245
switch (get_switches (gbuf, &lsw, &lnum)) { /* parse */
1124211246
case SW_ERROR:

0 commit comments

Comments
 (0)