]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[CLEANUP] acl, patterns: make use of my_strndup() instead of malloc+memcpy
authorWilly Tarreau <w@1wt.eu>
Tue, 26 Jan 2010 18:02:46 +0000 (19:02 +0100)
committerWilly Tarreau <w@1wt.eu>
Tue, 26 Jan 2010 18:02:46 +0000 (19:02 +0100)
This is simpler and more readable.

src/acl.c
src/pattern.c

index 0ded6bf82b7ca06f1521ef9c8ea5ca8a5f911a9c..0634d5d74489bf359ebbfc058c6143cedaa712e5 100644 (file)
--- a/src/acl.c
+++ b/src/acl.c
@@ -668,11 +668,8 @@ struct acl_expr *parse_acl_expr(const char **args)
                end = strchr(arg, ')');
                if (!end)
                        goto out_free_expr;
-               arg2 = (char *)calloc(1, end - arg + 1);
-               if (!arg2)
+               arg2 = my_strndup(arg, end - arg);
                        goto out_free_expr;
-               memcpy(arg2, arg, end - arg);
-               arg2[end-arg] = '\0';
                expr->arg_len = end - arg;
                expr->arg.str = arg2;
        }
index 5afd068e9472a14470988a4ddcff4577ec66527e..63bae2b8cada375a65e0d2534a3fa63d02663c07 100644 (file)
@@ -397,9 +397,7 @@ struct pattern_expr *pattern_parse_expr(char **str, int *idx)
 
        if (end != endw) {
                expr->arg_len = end - endw - 2;
-               expr->arg = malloc(expr->arg_len + 1);
-               expr->arg = memcpy(expr->arg, endw + 1, expr->arg_len);
-               expr->arg[expr->arg_len] = '\0';
+               expr->arg = my_strndup(endw + 1, expr->arg_len);
        }
 
        for (*idx += 1; *(str[*idx]); (*idx)++) {