]> git.ipfire.org Git - people/ric9/pakfire.git/commitdiff
parser: Don't try to expand empty strings
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 11 Jan 2025 14:10:45 +0000 (14:10 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 11 Jan 2025 14:10:45 +0000 (14:10 +0000)
This is just a fast path to avoid doing unnecessary work.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/parser.c

index a4984569a705d75a01117eee0ebe184175284211..5244de47513d502629586d150506f9228c964e4b 100644 (file)
@@ -599,10 +599,6 @@ static int pakfire_parser_expand_variables(struct pakfire_parser* parser,
        if (!buffer)
                return -EINVAL;
 
-       // There is nothing to expend on empty strings
-       else if (!*buffer)
-               return 0;
-
        // Compile the regular expression
        if (!regexes.variable) {
                r = pakfire_compile_regex(parser->ctx, &regexes.variable, "%\\{([A-Za-z0-9_\\-]+)\\}");
@@ -715,6 +711,10 @@ char* pakfire_parser_expand(struct pakfire_parser* parser,
        if (!buffer)
                goto ERROR;
 
+       // There is nothing to do for empty strings
+       if (!*buffer)
+               return buffer;
+
        // Fast path to check if there are any variables in here whatsoever
        char* pos = strchr(buffer, '%');
        if (!pos)