static int pakfire_parser_expand_variables(struct pakfire_parser* parser,
const char* namespace, char** buffer) {
- int r = 0;
PCRE2_UCHAR* variable = NULL;
- PCRE2_SIZE variable_length;
+ PCRE2_SIZE variable_length = 0;
PCRE2_UCHAR* pattern = NULL;
- PCRE2_SIZE pattern_length;
+ PCRE2_SIZE pattern_length = 0;
+ int r = 0;
+
+ // Do not work on an empty buffer
+ if (!buffer)
+ return -EINVAL;
+
+ // There is nothing to expend on empty strings
+ else if (!*buffer)
+ return 0;
// Allocate memory for results
pcre2_match_data* match = pcre2_match_data_create_from_pattern(
*buffer = tmp;
// Free resources
- pcre2_substring_free(variable);
+ if (variable)
+ pcre2_substring_free(variable);
variable = NULL;
- pcre2_substring_free(pattern);
+ if (pattern)
+ pcre2_substring_free(pattern);
pattern = NULL;
}
ERROR:
- pcre2_match_data_free(match);
-
+ if (match)
+ pcre2_match_data_free(match);
if (variable)
pcre2_substring_free(variable);
if (pattern)