1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2024-11-25 13:55:34 -05:00

Use asprintf.

Avoid possible errors.
This commit is contained in:
Qball Cow 2014-04-22 14:38:36 +02:00
parent 0d6556618e
commit 4fd76f59b4

View file

@ -56,11 +56,12 @@ static inline int execshssh ( const char *host )
int i=0; int i=0;
args[i++] = config.terminal_emulator; args[i++] = config.terminal_emulator;
if(config.show_title) { if(config.show_title) {
ssize_t length = strlen(host)+5; char *buffer = NULL;
char buffer[length]; if( asprintf(&buffer, "ssh %s", host) > 0)
snprintf(buffer, length, "ssh %s", host); {
args[i++] = strdup("-T"); args[i++] = strdup("-T");
args[i++] = strdup(buffer); args[i++] = buffer;
}
} }
args[i++] = strdup("-e"); args[i++] = strdup("-e");
args[i++] = strdup("ssh"); args[i++] = strdup("ssh");
@ -69,8 +70,10 @@ static inline int execshssh ( const char *host )
int retv = execvp ( config.terminal_emulator, (char * const *)args ); int retv = execvp ( config.terminal_emulator, (char * const *)args );
// Free the args list. // Free the args list.
for(int i =0; i < 7 && args[i] != NULL;i++) { for(int i =0; i < 7;i++) {
free(args[i]); if(args[i] != NULL) {
free(args[i]);
}
} }
free(args); free(args);
return retv; return retv;