diff options
author | Moshe Kaplan <me@moshekaplan.com> | 2020-08-07 19:32:16 -0400 |
---|---|---|
committer | Anders Broman <a.broman58@gmail.com> | 2020-08-08 09:54:29 +0000 |
commit | 3b47a55b0daeddb4edee6390387b0dfca1135be3 (patch) | |
tree | 98fdafc72394091a119250d4d5f0f7dbcde2ea3e /epan/exported_pdu.c | |
parent | 191e1f62d5b27123dae3f4488a5c2e2e799af0a0 (diff) |
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 <a.broman58@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'epan/exported_pdu.c')
-rw-r--r-- | epan/exported_pdu.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/epan/exported_pdu.c b/epan/exported_pdu.c index 431266ffe1..1b4d7d3e69 100644 --- a/epan/exported_pdu.c +++ b/epan/exported_pdu.c @@ -248,7 +248,7 @@ export_pdu_create_tags(packet_info *pinfo, const char* proto_name, guint16 tag_t DISSECTOR_ASSERT(proto_name != NULL); DISSECTOR_ASSERT((tag_type == EXP_PDU_TAG_PROTO_NAME) || (tag_type == EXP_PDU_TAG_HEUR_PROTO_NAME) || (tag_type == EXP_PDU_TAG_DISSECTOR_TABLE_NAME)); - exp_pdu_data = (exp_pdu_data_t *)wmem_alloc(wmem_packet_scope(), sizeof(exp_pdu_data_t)); + exp_pdu_data = wmem_new(wmem_packet_scope(), exp_pdu_data_t); /* Start by computing size of protocol name as a tag */ proto_str_len = (int)strlen(proto_name); |