]> git.ipfire.org Git - people/ric9/pakfire.git/commitdiff
parser: Cleanup expanding variables
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 11 Jan 2025 14:08:43 +0000 (14:08 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 11 Jan 2025 14:08:43 +0000 (14:08 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/parser.c

index b6a862f149e10bc1a77d3d40edc12143d8799f8b..a4984569a705d75a01117eee0ebe184175284211 100644 (file)
@@ -703,6 +703,7 @@ ERROR:
 
 char* pakfire_parser_expand(struct pakfire_parser* parser,
                const char* namespace, const char* value) {
+       char* buffer = NULL;
        int r;
 
        // Return NULL when the value is NULL
@@ -710,25 +711,27 @@ char* pakfire_parser_expand(struct pakfire_parser* parser,
                return NULL;
 
        // Create a working copy of the string we are expanding
-       char* buffer = strdup(value);
+       buffer = strdup(value);
+       if (!buffer)
+               goto ERROR;
 
        // Fast path to check if there are any variables in here whatsoever
-       char* pos = strchr(value, '%');
+       char* pos = strchr(buffer, '%');
        if (!pos)
                return buffer;
 
        // Expand all variables
        r = pakfire_parser_expand_variables(parser, namespace, &buffer);
-       if (r) {
-               DEBUG(parser->ctx, "Failed to expand variables in '%s': %m\n", value);
+       if (r < 0) {
+               DEBUG(parser->ctx, "Failed to expand variables in '%s': %s\n", value, strerror(-r));
                goto ERROR;
        }
 
        // Expand all commands
        if (parser->flags & PAKFIRE_PARSER_FLAGS_EXPAND_COMMANDS) {
                r = pakfire_parser_expand_commands(parser, &buffer);
-               if (r) {
-                       DEBUG(parser->ctx, "Failed to expand commands in '%s': %m\n", value);
+               if (r < 0) {
+                       DEBUG(parser->ctx, "Failed to expand commands in '%s': %s\n", value, strerror(-r));
                        goto ERROR;
                }
        }