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. --- epan/print_stream.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'epan/print_stream.c') diff --git a/epan/print_stream.c b/epan/print_stream.c index 3c3cb74092..a694216171 100644 --- a/epan/print_stream.c +++ b/epan/print_stream.c @@ -664,7 +664,7 @@ print_stream_text_alloc(gboolean to_file, FILE *fh) output->color_type = COLOR_NONE; } - stream = (print_stream_t *)g_malloc(sizeof (print_stream_t)); + stream = g_new(print_stream_t, 1); stream->ops = &print_text_ops; stream->data = output; @@ -834,7 +834,7 @@ print_stream_ps_alloc(gboolean to_file, FILE *fh) output->to_file = to_file; output->fh = fh; - stream = (print_stream_t *)g_malloc(sizeof (print_stream_t)); + stream = g_new(print_stream_t, 1); stream->ops = &print_ps_ops; stream->data = output; -- cgit v1.2.3