From e16166a74cca1d66e2c302e257cf94aebb380599 Mon Sep 17 00:00:00 2001 From: Moshe Kaplan Date: Sun, 20 Dec 2020 21:30:28 -0500 Subject: Detect and replace bad allocation patterns Adds a pre-commit hook for detecting and replacing occurrences of `g_malloc()` and `wmem_alloc()` with `g_new()` and `wmem_new()`, to improve the readability of Wireshark's code, and occurrences of `g_malloc(sizeof(struct myobj) * foo)` with `g_new(struct myobj, foo)` to prevent integer overflows Also fixes all existing occurrences across the codebase. --- capchild/capture_ifinfo.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'capchild') diff --git a/capchild/capture_ifinfo.c b/capchild/capture_ifinfo.c index a60fe6fb5d..e8f049818a 100644 --- a/capchild/capture_ifinfo.c +++ b/capchild/capture_ifinfo.c @@ -40,12 +40,12 @@ static GList * append_remote_list(GList *iflist) for (rlist = g_list_nth(remote_interface_list, 0); rlist != NULL; rlist = g_list_next(rlist)) { if_info = (if_info_t *)rlist->data; - temp = (if_info_t*) g_malloc0(sizeof(if_info_t)); + temp = g_new0(if_info_t, 1); temp->name = g_strdup(if_info->name); temp->friendly_name = g_strdup(if_info->friendly_name); temp->vendor_description = g_strdup(if_info->vendor_description); for (list = g_slist_nth(if_info->addrs, 0); list != NULL; list = g_slist_next(list)) { - temp_addr = (if_addr_t *) g_malloc0(sizeof(if_addr_t)); + temp_addr = g_new0(if_addr_t, 1); if_addr = (if_addr_t *)list->data; if (if_addr) { temp_addr->ifat_type = if_addr->ifat_type; @@ -342,12 +342,12 @@ void add_interface_to_remote_list(if_info_t *if_info) GSList *list; if_addr_t *if_addr, *temp_addr; - if_info_t *temp = (if_info_t*) g_malloc0(sizeof(if_info_t)); + if_info_t *temp = g_new0(if_info_t, 1); temp->name = g_strdup(if_info->name); temp->friendly_name = g_strdup(if_info->friendly_name); temp->vendor_description = g_strdup(if_info->vendor_description); for (list = g_slist_nth(if_info->addrs, 0); list != NULL; list = g_slist_next(list)) { - temp_addr = (if_addr_t *)g_malloc0(sizeof(if_addr_t)); + temp_addr = g_new0(if_addr_t, 1); if_addr = (if_addr_t *)list->data; if (if_addr) { temp_addr->ifat_type = if_addr->ifat_type; -- cgit v1.2.3