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:
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user