Skip to content

Commit

Permalink
replaced several unsafe strcat() calls
Browse files Browse the repository at this point in the history
  • Loading branch information
seansweda committed Mar 10, 2017
1 parent f4def66 commit 172f5f1
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 22 deletions.
7 changes: 2 additions & 5 deletions frame.cc
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,6 @@ frame::runcat(int adv)
temptr=temp;
*temptr='\0';


switch (adv) {
case 0 : // batter out
strcat(baserunning,"bo");
Expand All @@ -496,7 +495,6 @@ frame::runcat(int adv)
else
strcat(baserunning,"b112233h");
break;
//else {

case -2 : // runners advance 1 base
for (i=1;i<=3;i++)
Expand All @@ -510,7 +508,6 @@ frame::runcat(int adv)
break;

case -3 :
// strcat(baserunning,"1o");
for (i=1;i<=3;i++)
if (onbase[i]) test=i;
sprintf(temptr++,"%1d",test);
Expand Down Expand Up @@ -545,7 +542,7 @@ frame::runcat(int adv)
} // switch

*temptr='\0';
strcat(baserunning,temp);
snprintf( baserunning + strlen(baserunning), MAX_INPUT, "%s", temp);
}

int
Expand Down Expand Up @@ -826,7 +823,7 @@ frame::outbuf( FILE *fp, const char *str, const char *punc )
buffer[c] = '\0';
ptr++;

buffer = strcat( buffer, "\n" );
strcat( buffer, "\n" );
fputs( buffer, fp );
strncpy( tempstr, ptr, MAX_INPUT * 2 );
}
Expand Down
3 changes: 1 addition & 2 deletions player.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ player::new_pos( char *newpos )
{
// extend pos string
pos = (char*) realloc( pos, strlen(pos) + strlen(newpos) + 2 );
strcat( pos, "-" );
strcat( pos, newpos );
snprintf( pos + strlen(pos), 4, "-%s", newpos );
posn = getpos( newpos );
}

Expand Down
12 changes: 5 additions & 7 deletions team.cc
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,7 @@ team::pos_change( int spot, char **comment )
#ifdef DEBUG
fprintf( stderr, "pos_change %d: %s DONE\n", spot, pos );
#endif
sprintf( tempstr, "%s moves to %s.", oldpl->head->nout(), pos );
strcat( *comment, tempstr );
snprintf( *comment, MAX_INPUT, "%s moves to %s.", oldpl->head->nout(), pos );
}

// Adds a new player at position "spot" in the batting order
Expand Down Expand Up @@ -181,23 +180,23 @@ team::insert( int spot, char **comment, const char *def, const char *inputstr )

if ( !(strcmp(pos, def)) ) {
newpl->head = new player( name, ibl, mlb, def );
sprintf( tempstr, "%s %s for %s, batting %d.",
snprintf( *comment, MAX_INPUT, "%s %s for %s, batting %d.",
name, def, oldpl->head->nout(), spot );
}
else if ( pos[0] == 'p' ) {
newpl->head = new player( name, ibl, mlb, pos );
sprintf( tempstr, "%s now pitching for %s, batting %d.",
snprintf( *comment, MAX_INPUT, "%s now pitching for %s, batting %d.",
name, ibl, spot );
}
else if ( def[0] == '\0' ) {
newpl->head = new player( name, ibl, mlb, pos );
sprintf( tempstr, "%s now %s for %s, batting %d.",
snprintf( *comment, MAX_INPUT, "%s now %s for %s, batting %d.",
name, pos, ibl, spot );
}
else {
newpl->head = new player( name, ibl, mlb, def );
newpl->head->new_pos(pos);
sprintf( tempstr, "%s %s for %s, batting %d.",
snprintf( *comment, MAX_INPUT, "%s %s for %s, batting %d.",
name, def, oldpl->head->nout(), spot);
}

Expand All @@ -209,7 +208,6 @@ team::insert( int spot, char **comment, const char *def, const char *inputstr )
#ifdef DEBUG
fprintf( stderr, "insert %d: %s, %s, %s DONE\n", spot, name, mlb, pos );
#endif
strcat( *comment, tempstr );
}

// Creates the lineups for a team
Expand Down
16 changes: 8 additions & 8 deletions update.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ frame::update()
onbase[0]=bat->up();
runadv();
frameput();
strcat( comment, " " );
outbuf( pbpfp, comment );
snprintf( tempstr, MAX_INPUT, "%s ", comment );
outbuf( pbpfp, tempstr );
return(1);
}
else if ( !(strcmp( event, "pr" )) ) {
Expand All @@ -57,8 +57,8 @@ frame::update()
onbase[i] = ibl[atbat]->findord(tempstr[0] - '0');
runadv();
frameput();
strcat( comment, " " );
outbuf( pbpfp, comment );
snprintf( tempstr, MAX_INPUT, "%s ", comment );
outbuf( pbpfp, tempstr );
return(1);
}
}
Expand All @@ -79,8 +79,8 @@ frame::update()
}
runadv();
frameput();
strcat( comment, " " );
outbuf( pbpfp, comment );
snprintf( tempstr, MAX_INPUT, "%s ", comment );
outbuf( pbpfp, tempstr );
return(1);
}
else if ( !(strcmp( event, "dr" )) || !(strcmp( event, "dc" )) ) {
Expand All @@ -99,8 +99,8 @@ frame::update()
}
runadv();
frameput();
strcat( comment, " " );
outbuf( pbpfp, comment );
snprintf( tempstr, MAX_INPUT, "%s ", comment );
outbuf( pbpfp, tempstr );
return(1);
}
else if ( !(strcmp( event, "la" )) ) {
Expand Down

0 comments on commit 172f5f1

Please sign in to comment.