refactor: replace calloc with g_new0 for struct allocations

Migrate structure allocations from calloc to glibs g_new0 macro to
improve type safety and memory robustness.

* Type Safety: The macro takes the type name directly, ensuring the
  allocated size always matches the pointer type.
* Static Analysis: It guarantees a non-NULL return by aborting on
  failure, which silences -fanalyzer warnings regarding potential NULL
  pointer dereferences.
* Readability: Removes redundant sizeof() calls and is the glib way
This commit is contained in:
Michael Vetter
2026-02-26 16:49:53 +01:00
parent f1d4ed41d6
commit e1fd2a1cf6
13 changed files with 38 additions and 38 deletions

View File

@@ -19,15 +19,15 @@ void
returns_commands(void** state)
{
plugins_init();
PluginCommand* command1 = calloc(1, sizeof(PluginCommand));
PluginCommand* command1 = g_new0(PluginCommand, 1);
command1->command_name = strdup("command1");
callbacks_add_command("plugin1", command1);
PluginCommand* command2 = calloc(1, sizeof(PluginCommand));
PluginCommand* command2 = g_new0(PluginCommand, 1);
command2->command_name = strdup("command2");
callbacks_add_command("plugin1", command2);
PluginCommand* command3 = calloc(1, sizeof(PluginCommand));
PluginCommand* command3 = g_new0(PluginCommand, 1);
command3->command_name = strdup("command3");
callbacks_add_command("plugin2", command3);

View File

@@ -87,7 +87,7 @@ handle_offline_removes_chat_session(void** state)
Resource* resourcep = resource_new(resource, RESOURCE_ONLINE, NULL, 10);
roster_update_presence(barejid, resourcep, NULL);
chat_session_recipient_active(barejid, resource, FALSE);
ProfConsoleWin* console = calloc(1, sizeof(ProfConsoleWin));
ProfConsoleWin* console = g_new0(ProfConsoleWin, 1);
will_return(win_create_console, &console->window);
wins_init();
sv_ev_contact_offline(barejid, resource, NULL);