[X2Go-Commits] [nx-libs] 25/29: Keyboard.c: rework string allocation/building
git-admin at x2go.org
git-admin at x2go.org
Sun Jan 7 01:31:00 CET 2018
This is an automated email from the git hooks/post-receive script.
x2go pushed a commit to branch 3.6.x
in repository nx-libs.
commit 11b2b067e017c55f9b1b275671198336847f14e0
Author: Ulrich Sibiller <uli42 at gmx.de>
Date: Wed Jan 3 02:22:11 2018 +0100
Keyboard.c: rework string allocation/building
---
nx-X11/programs/Xserver/hw/nxagent/Keyboard.c | 24 ++++++++++--------------
1 file 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 cddb345..3acf498 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
--
Alioth's /home/x2go-admin/maintenancescripts/git/hooks/post-receive-email on /srv/git/code.x2go.org/nx-libs.git
More information about the x2go-commits
mailing list