diff options
author | Moshe Kaplan <me@moshekaplan.com> | 2020-12-20 21:30:28 -0500 |
---|---|---|
committer | AndersBroman <a.broman58@gmail.com> | 2020-12-22 14:56:38 +0000 |
commit | e16166a74cca1d66e2c302e257cf94aebb380599 (patch) | |
tree | 8834b4b8390fca83dd7bc1b4b9e6a7bb276e1d7e /capchild | |
parent | 7b27b444cbd94853b399da770e0dad4b91ef23ac (diff) |
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.
Diffstat (limited to 'capchild')
-rw-r--r-- | capchild/capture_ifinfo.c | 8 |
1 files changed, 4 insertions, 4 deletions
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; |