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
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;
}
}