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. --- rawshark.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'rawshark.c') diff --git a/rawshark.c b/rawshark.c index 1a573d3ce3..4f6585603d 100644 --- a/rawshark.c +++ b/rawshark.c @@ -1300,7 +1300,7 @@ protocolinfo_init(char *field) ftenum_to_string(hfi), hfibuf); - rs=(pci_t *)g_malloc(sizeof(pci_t)); + rs=g_new(pci_t, 1); rs->hf_index=hfi->id; rs->filter=field; rs->cmd_line_index = g_cmd_line_index++; @@ -1327,7 +1327,7 @@ protocolinfo_init(char *field) static void add_string_fmt(string_fmt_e format, gchar *plain) { - string_fmt_t *sf = (string_fmt_t *)g_malloc(sizeof(string_fmt_t)); + string_fmt_t *sf = g_new(string_fmt_t, 1); sf->format = format; sf->plain = g_strdup(plain); -- cgit v1.2.3