rules: use asprintf instead of _Concat function Signed-off-by: Ran Benita <ran234@gmail.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
diff --git a/src/xkbcomp/rules.c b/src/xkbcomp/rules.c
index 14a2114..107f602 100644
--- a/src/xkbcomp/rules.c
+++ b/src/xkbcomp/rules.c
@@ -565,20 +565,6 @@ match_line(struct input_line *line, struct mapping *mapping,
return false;
}
-static char *
-_Concat(char *str1,char *str2)
-{
- int len;
-
- if ((!str1)||(!str2))
- return str1;
- len= strlen(str1)+strlen(str2)+1;
- str1 = uTypedRealloc(str1, len, char);
- if (str1)
- strcat(str1,str2);
- return str1;
-}
-
static void
squeeze_spaces(char *p1)
{
@@ -659,13 +645,21 @@ FreeMultiDefs(struct multi_defs *defs)
static void
Apply(char *src, char **dst)
{
- if (src) {
- if (*src == '+' || *src == '!') {
- *dst= _Concat(*dst, src);
- } else {
- if (*dst == NULL)
- *dst= uDupString(src);
- }
+ int ret;
+ char *tmp;
+
+ if (!src)
+ return;
+
+ if (*src == '+' || *src == '!') {
+ tmp = *dst;
+ ret = asprintf(dst, "%s%s", *dst, src);
+ if (ret < 0)
+ *dst = NULL;
+ free(tmp);
+ }
+ else if (*dst == NULL) {
+ *dst = uDupString(src);
}
}