static void report_unsupported_feature(Error **errp, Qcow2Feature *table,
uint64_t mask)
{
- char *features = g_strdup("");
- char *old;
+ g_autoptr(GString) features = g_string_sized_new(60);
while (table && table->name[0] != '\0') {
if (table->type == QCOW2_FEAT_TYPE_INCOMPATIBLE) {
if (mask & (1ULL << table->bit)) {
- old = features;
- features = g_strdup_printf("%s%s%.46s", old, *old ? ", " : "",
- table->name);
- g_free(old);
+ if (features->len > 0) {
+ g_string_append(features, ", ");
+ }
+ g_string_append_printf(features, "%.46s", table->name);
mask &= ~(1ULL << table->bit);
}
}
}
if (mask) {
- old = features;
- features = g_strdup_printf("%s%sUnknown incompatible feature: %" PRIx64,
- old, *old ? ", " : "", mask);
- g_free(old);
+ if (features->len > 0) {
+ g_string_append(features, ", ");
+ }
+ g_string_append_printf(features,
+ "Unknown incompatible feature: %" PRIx64, mask);
}
- error_setg(errp, "Unsupported qcow2 feature(s): %s", features);
- g_free(features);
+ error_setg(errp, "Unsupported qcow2 feature(s): %s", features->str);
}
/*