Convert strcat()s to snprintf()s. Issue #6

This commit is contained in:
Morgan Aldridge 2020-12-27 11:30:39 -05:00
parent 7c8f22ff56
commit 5ed03df783

View File

@ -545,10 +545,11 @@ void DoStartFunc( void )
int main( int argc, char *argv[] )
{
char *display_name=NULL;
char *display_screen;
char *display_string;
char *config_file=NULL;
char message[255];
char num[10];
char *cp;
Window StartWin;
XSetWindowAttributes attributes;
int len, lp;
@ -614,19 +615,29 @@ int main( int argc, char *argv[] )
if(!single){
for(lp=0;lp<Scr.NumberOfScreens;lp++){
if(lp!= Scr.screen){
snprintf(message, sizeof(message), "%s -d %s", argv[0], XDisplayString(dpy));
len = strlen(message);
message[len-1] = '\0';
sprintf(num,"%d",lp);
strcat(message,num);
strcat(message," -s ");
if( Scr.flags & DEBUGOUT)
strcat(message," -debug");
if( config_file!=NULL ){
strcat(message," -f ");
strcat(message,config_file);
len = strlen(XDisplayString(dpy)) + 10;
display_screen = calloc(len, sizeof(char));
snprintf(display_screen, len, "%s", XDisplayString(dpy));
/*
* Truncate the string 'whatever:n.n' to 'whatever:n',
* and then append the screen number.
*/
cp = strchr(display_screen, ':');
if (cp != NULL)
{
cp = strchr(cp, '.');
if (cp != NULL)
*cp = '\0'; /* truncate at display part */
}
strcat(message," &\n");
snprintf(message, sizeof(message), "%s -d %s.%d -s", argv[0], display_screen, lp);
free(display_screen);
if( Scr.flags & DEBUGOUT)
snprintf(message + strlen(message), sizeof(message) - strlen(message), " -debug");
if( config_file != NULL )
snprintf(message + strlen(message), sizeof(message) - strlen(message) ," -f %s", config_file);
snprintf(message + strlen(message), sizeof(message) - strlen(message), " &\n");
system(message);
}
}