From 3b47a55b0daeddb4edee6390387b0dfca1135be3 Mon Sep 17 00:00:00 2001 From: Moshe Kaplan Date: Fri, 7 Aug 2020 19:32:16 -0400 Subject: Replace instances of wmem_alloc with wmem_new This commit replaces instances of (myobj *)wmem_alloc(wmem_X_scope(), sizeof(myobj)) and replaces them with: wmem_new(wmem_X_scope(), myobj) to improve the readability of Wireshark's code. Replacements were made with the following Python script: import os import re import sys pattern = r'\(([^\s\n]+) ?\*\) ?wmem_alloc(0?)\((wmem_[a-z]+_scope\(\)), sizeof\(\1\)\)' replacewith = r'wmem_new\2(\3, \1)' startdir = sys.argv[1] for root, dirs, files in os.walk(startdir): for fname in files: fpath = os.path.join(root, fname) if not fpath.endswith('.c'): continue with open(fpath, 'r') as fh: fdata = fh.read() output = re.sub(pattern, replacewith, fdata) if fdata != output: print(fpath) with open(fpath, 'w') as fh: fh.write(output) Change-Id: I223cb2fcce336bc99ca21c4a74e4cf758fd00572 Reviewed-on: https://code.wireshark.org/review/38088 Petri-Dish: Anders Broman Tested-by: Petri Dish Buildbot Reviewed-by: Anders Broman --- plugins/epan/unistim/packet-unistim.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins') diff --git a/plugins/epan/unistim/packet-unistim.c b/plugins/epan/unistim/packet-unistim.c index 4ebad9a158..6c2563142a 100644 --- a/plugins/epan/unistim/packet-unistim.c +++ b/plugins/epan/unistim/packet-unistim.c @@ -194,7 +194,7 @@ dissect_unistim(tvbuff_t *tvb,packet_info *pinfo,proto_tree *tree,void *data _U_ proto_tree_add_item(rudpm_tree,hf_unistim_seq_nu,tvb,offset,4,ENC_BIG_ENDIAN); /* Allocate new mem for queueing */ - uinfo = (unistim_info_t *)wmem_alloc(wmem_packet_scope(), sizeof(unistim_info_t)); + uinfo = wmem_new(wmem_packet_scope(), unistim_info_t); /* Clear tap struct */ uinfo->rudp_type = 0; -- cgit v1.2.3