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

@@ -111,7 +111,7 @@ api_register_command(const char* const plugin_name, const char* command_name, in
char** synopsis, const char* description, char* arguments[][2], char** examples,
void* callback, void (*callback_exec)(PluginCommand* command, gchar** args), void (*callback_destroy)(void* callback))
{
PluginCommand* command = calloc(1, sizeof(PluginCommand));
PluginCommand* command = g_new0(PluginCommand, 1);
command->command_name = strdup(command_name);
command->min_args = min_args;
command->max_args = max_args;
@@ -119,7 +119,7 @@ api_register_command(const char* const plugin_name, const char* command_name, in
command->callback_exec = callback_exec;
command->callback_destroy = callback_destroy;
CommandHelp* help = calloc(1, sizeof(CommandHelp));
CommandHelp* help = g_new0(CommandHelp, 1);
int i;
for (i = 0; synopsis[i] != NULL; i++) {