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

index 90302d7685e3821a5fbc1d4265896befbd3fa258..737ad37433c6784e7c07560ceba2110a425cdc1d 100644 (file)
@@ -668,22 +668,25 @@ static int pakfire_parser_expand_variables(struct pakfire_parser* parser,
 #endif /* PAKFIRE_DEBUG_PARSER */
 
                // Replace all occurrences
-               char* tmp = pakfire_string_replace(*buffer, (const char*)pattern, (repl) ? repl : "");
-               if (!tmp)
+               char* tmp = pakfire_string_replace(*buffer, (const char*)pattern, repl);
+               if (!tmp) {
+                       r = -errno;
                        goto ERROR;
+               }
 
                // Replace buffer
                free(*buffer);
                *buffer = tmp;
 
                // Free resources
-               if (variable)
+               if (variable) {
                        pcre2_substring_free(variable);
-               variable = NULL;
-
-               if (pattern)
+                       variable = NULL;
+               }
+               if (pattern) {
                        pcre2_substring_free(pattern);
-               pattern = NULL;
+                       pattern = NULL;
+               }
        }
 
 ERROR: