}
static void pakfire_transaction_add_headline(char** str, size_t width, const char* headline) {
- asprintf(str, "%s%s\n", *str, headline);
+ asprintf(str, "%s%s\n", strdup(*str), headline);
}
static void pakfire_transaction_add_newline(char** str, size_t width) {
- asprintf(str, "%s\n", *str);
+ asprintf(str, "%s\n", strdupa(*str));
}
static void pakfire_transaction_add_line(char** str, size_t width, const char* name,
const char* arch, const char* version, const char* repo, const char* size) {
// XXX need to adapt to size
- asprintf(str, "%s %-21s %-8s %-21s %-18s %6s \n", *str, name, arch, version, repo, size);
+ asprintf(str, "%s %-21s %-8s %-21s %-18s %6s \n", strdupa(*str),
+ name, arch, version, repo, size);
}
static void pakfire_transaction_add_package(char** str, size_t width, PakfirePackage pkg) {
// Print the new package first
pakfire_transaction_add_package(str, width, new_pkg);
- asprintf(str, "%s --> %s\n", *str, pakfire_package_get_nevra(old_pkg));
+ asprintf(str, "%s --> %s\n", strdupa(*str), pakfire_package_get_nevra(old_pkg));
}
static void pakfire_transaction_add_separator(char** str, size_t width) {
- while (width-- > 0)
- asprintf(str, "%s=", *str);
+ char* separator = alloca(width + 1);
+
+ // Make separator of appropriate length
+ for (unsigned int i = 0; i < width; i++)
+ separator[i] = '=';
+ separator[width] = '\0';
// newline
- asprintf(str, "%s\n", *str);
+ asprintf(str, "%s%s\n", strdupa(*str), separator);
}
static void pakfire_transaction_add_usage_line(char** str, size_t width, const char* headline, ssize_t size) {
char buffer[128];
pakfire_format_size(buffer, sizeof(buffer) - 1, size);
- asprintf(str, "%s%-21s: %s\n", *str, headline, buffer);
+ asprintf(str, "%s%-21s: %s\n", strdupa(*str), headline, buffer);
}
PAKFIRE_EXPORT char* pakfire_transaction_dump(struct pakfire_transaction* transaction, size_t width) {
char headline[1024];
- char* string = "";
+ char* string = strdup("");
Pool* pool = transaction->transaction->pool;
const int mode =