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 /wiretap/netxray.c | |
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 'wiretap/netxray.c')
-rw-r--r-- | wiretap/netxray.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/wiretap/netxray.c b/wiretap/netxray.c index 368575a721..dd940785d2 100644 --- a/wiretap/netxray.c +++ b/wiretap/netxray.c @@ -836,7 +836,7 @@ netxray_open(wtap *wth, int *err, gchar **err_info) /* This is a netxray file */ wth->file_type_subtype = file_type; - netxray = (netxray_t *)g_malloc(sizeof(netxray_t)); + netxray = g_new(netxray_t, 1); wth->priv = (void *)netxray; wth->subtype_read = netxray_read; wth->subtype_seek_read = netxray_seek_read; @@ -1714,7 +1714,7 @@ netxray_dump_open_1_1(wtap_dumper *wdh, int *err, gchar **err_info _U_) return FALSE; wdh->bytes_dumped += CAPTUREFILE_HEADER_SIZE; - netxray = (netxray_dump_t *)g_malloc(sizeof(netxray_dump_t)); + netxray = g_new(netxray_dump_t, 1); wdh->priv = (void *)netxray; netxray->first_frame = TRUE; netxray->start.secs = 0; @@ -1901,7 +1901,7 @@ netxray_dump_open_2_0(wtap_dumper *wdh, int *err, gchar **err_info _U_) wdh->bytes_dumped += CAPTUREFILE_HEADER_SIZE; - netxray = (netxray_dump_t *)g_malloc(sizeof(netxray_dump_t)); + netxray = g_new(netxray_dump_t, 1); wdh->priv = (void *)netxray; netxray->first_frame = TRUE; netxray->start.secs = 0; |