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. --- wiretap/visual.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'wiretap/visual.c') diff --git a/wiretap/visual.c b/wiretap/visual.c index 98f4e680b3..8fd7613b0a 100644 --- a/wiretap/visual.c +++ b/wiretap/visual.c @@ -246,7 +246,7 @@ wtap_open_return_val visual_open(wtap *wth, int *err, gchar **err_info) wth->file_tsprec = WTAP_TSPREC_MSEC; /* Add Visual-specific information to the wiretap struct for later use. */ - visual = (struct visual_read_info *)g_malloc(sizeof(struct visual_read_info)); + visual = g_new(struct visual_read_info, 1); wth->priv = (void *)visual; visual->num_pkts = pletoh32(&vfile_hdr.num_pkts); visual->start_time = pletoh32(&vfile_hdr.start_time); @@ -612,7 +612,7 @@ gboolean visual_dump_open(wtap_dumper *wdh, int *err, gchar **err_info _U_) /* Create a struct to hold file information for the duration of the write */ - visual = (struct visual_write_info *)g_malloc(sizeof(struct visual_write_info)); + visual = g_new(struct visual_write_info, 1); wdh->priv = (void *)visual; visual->index_table_index = 0; visual->index_table_size = 1024; -- cgit v1.2.3