Commit 2836c72f authored by Ulrich Sibiller's avatar Ulrich Sibiller

Keyboard.c: replace malloc + strcpy by asprintf

parent 08912ef3
...@@ -1899,18 +1899,16 @@ void nxagentKeycodeConversionSetup(void) ...@@ -1899,18 +1899,16 @@ void nxagentKeycodeConversionSetup(void)
char *sessionpath = nxagentGetSessionPath(); char *sessionpath = nxagentGetSessionPath();
if (sessionpath) if (sessionpath)
{ {
int keyboard_file_path_size = strlen(sessionpath) + strlen("/keyboard"); char *keyboard_file_path = NULL;
char *keyboard_file_path = malloc((keyboard_file_path_size + 1) * sizeof(char));
FILE *keyboard_file; FILE *keyboard_file;
if (!keyboard_file_path) if ((asprintf(&keyboard_file_path, "%s/keyboard", sessionpath) == -1))
{ {
free(sessionpath); free(sessionpath);
FatalError("malloc for keyboard file path failed."); FatalError("malloc for keyboard file path failed.");
} }
strcpy(keyboard_file_path, sessionpath);
strcat(keyboard_file_path, "/keyboard");
free(sessionpath); free(sessionpath);
if ((keyboard_file = fopen(keyboard_file_path, "w"))) { if ((keyboard_file = fopen(keyboard_file_path, "w")))
{
if (drules) if (drules)
fprintf(keyboard_file, "rules=\"%s\"\n", drules[0] == '\0' ? "," : drules); fprintf(keyboard_file, "rules=\"%s\"\n", drules[0] == '\0' ? "," : drules);
if (dmodel) if (dmodel)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment