Adapt to g_string_free glib 2.75.3 change

glib 2.75.3 changes warning behaviour of `g_string_free()`.
See:
* https://gitlab.gnome.org/GNOME/glib/-/merge_requests/3219
* https://gitlab.gnome.org/GNOME/glib/-/merge_requests/3226

Use this opportunity to replace the use of GString with
`g_strdup_printf()` where possible.
Otherwise correctly take the return value of `g_string_free()`
which is nicer anyways.
This commit is contained in:
Michael Vetter
2023-03-17 23:58:33 +01:00
parent e5e8ff221a
commit e59c401c84
17 changed files with 44 additions and 147 deletions

View File

@@ -214,22 +214,18 @@ p_contact_name_or_jid(const PContact contact)
char*
p_contact_create_display_string(const PContact contact, const char* const resource)
{
GString* result_str = g_string_new("");
gchar* result;
// use nickname if exists
const char* display_name = p_contact_name_or_jid(contact);
g_string_append(result_str, display_name);
// add resource if not default provided by profanity
if (strcmp(resource, "__prof_default") != 0) {
g_string_append(result_str, " (");
g_string_append(result_str, resource);
g_string_append(result_str, ")");
result = g_strdup_printf("%s (%s)", display_name, resource);
} else {
result = g_strdup_printf("%s", display_name);
}
char* result = result_str->str;
g_string_free(result_str, FALSE);
return result;
}

View File

@@ -572,12 +572,10 @@ iq_send_caps_request_legacy(const char* const to, const char* const id,
return;
}
GString* node_str = g_string_new("");
g_string_printf(node_str, "%s#%s", node, ver);
xmpp_stanza_t* iq = stanza_create_disco_info_iq(ctx, id, to, node_str->str);
gchar* node_str = g_strdup_printf("%s#%s", node, ver);
xmpp_stanza_t* iq = stanza_create_disco_info_iq(ctx, id, to, node_str);
iq_id_handler_add(id, _caps_response_legacy_id_handler, g_free, node_str->str);
g_string_free(node_str, FALSE);
iq_id_handler_add(id, _caps_response_legacy_id_handler, g_free, node_str);
iq_send_stanza(iq);
xmpp_stanza_release(iq);

View File

@@ -749,9 +749,7 @@ muc_autocomplete(ProfWin* window, const char* const input, gboolean previous)
g_string_append(replace_with, ": ");
}
g_free(result);
result = replace_with->str;
g_string_free(replace_with, FALSE);
return result;
return g_string_free(replace_with, FALSE);
}
void

View File

@@ -188,10 +188,7 @@ roster_get_display_name(const char* const barejid)
g_string_append(result, barejid);
}
char* result_str = result->str;
g_string_free(result, FALSE);
return result_str;
return g_string_free(result, FALSE);
}
char*
@@ -223,10 +220,7 @@ roster_get_msg_display_name(const char* const barejid, const char* const resourc
g_string_append(result, resource);
}
char* result_str = result->str;
g_string_free(result, FALSE);
return result_str;
return g_string_free(result, FALSE);
}
gboolean