aboutsummaryrefslogtreecommitdiff
path: root/nx-X11/programs/Xserver/hw
diff options
context:
space:
mode:
authorUlrich Sibiller <uli42@gmx.de>2018-01-03 02:22:11 +0100
committerUlrich Sibiller <uli42@gmx.de>2018-01-07 01:27:07 +0100
commit11b2b067e017c55f9b1b275671198336847f14e0 (patch)
treeea2ad3c553ebff9c6190ea66ddf9cd8d8d74ea27 /nx-X11/programs/Xserver/hw
parenta0e985fb6d28c1ef551823e3b2a013b29192ac02 (diff)
downloadnx-libs-11b2b067e017c55f9b1b275671198336847f14e0.tar.gz
nx-libs-11b2b067e017c55f9b1b275671198336847f14e0.tar.bz2
nx-libs-11b2b067e017c55f9b1b275671198336847f14e0.zip
Keyboard.c: rework string allocation/building
Diffstat (limited to 'nx-X11/programs/Xserver/hw')
-rw-r--r--nx-X11/programs/Xserver/hw/nxagent/Keyboard.c24
1 files changed, 10 insertions, 14 deletions
diff --git a/nx-X11/programs/Xserver/hw/nxagent/Keyboard.c b/nx-X11/programs/Xserver/hw/nxagent/Keyboard.c
index cddb3457e..3acf498ff 100644
--- a/nx-X11/programs/Xserver/hw/nxagent/Keyboard.c
+++ b/nx-X11/programs/Xserver/hw/nxagent/Keyboard.c
@@ -534,7 +534,6 @@ static void nxagentCheckXkbBaseDirectory(void)
static char *nxagentXkbGetRules()
{
int ret;
- int size, sizeDflt, sizeAlt;
char *path;
struct stat buf;
@@ -543,19 +542,11 @@ static char *nxagentXkbGetRules()
XkbBaseDirectory);
#endif
- sizeDflt = strlen(XKB_DFLT_RULES_FILE);
- sizeAlt = strlen(XKB_ALTS_RULES_FILE);
- size = strlen(XkbBaseDirectory) + strlen("/rules/");
- size += (sizeDflt > sizeAlt) ? sizeDflt : sizeAlt;
-
- if ((path = malloc((size + 1) * sizeof(char))) == NULL)
+ if (-1 == asprintf(&path, "%s/rules/%s", XkbBaseDirectory, XKB_DFLT_RULES_FILE))
{
FatalError("nxagentXkbGetRules: malloc failed.");
}
- strcpy(path, XkbBaseDirectory);
- strcat(path, "/rules/");
- strcat(path, XKB_DFLT_RULES_FILE);
#ifdef TEST
fprintf(stderr, "nxagentXkbGetRules: checking rules file [%s]\n", path);
#endif
@@ -572,11 +563,16 @@ static char *nxagentXkbGetRules()
#ifdef TEST
fprintf(stderr, "nxagentXkbGetRules: WARNING! Failed to stat file [%s]: %s.\n", path, strerror(ret));
- #endif
+ #endif
+
+ free(path);
+ path = NULL;
+
+ if (-1 == asprintf(&path, "%s/rules/%s", XkbBaseDirectory, XKB_ALTS_RULES_FILE))
+ {
+ FatalError("nxagentXkbGetRules: malloc failed.");
+ }
- strcpy(path, XkbBaseDirectory);
- strcat(path, "/rules/");
- strcat(path, XKB_ALTS_RULES_FILE);
#ifdef TEST
fprintf(stderr, "nxagentXkbGetRules: checking rules file [%s]\n", path);
#endif