From fd7895d37c2410f81231efdfd8b0640c15887a70 Mon Sep 17 00:00:00 2001 From: Moshe Kaplan Date: Thu, 7 May 2020 08:35:45 -0400 Subject: Replace instances of wmem_alloc with wmem_new This commit replaces instances of (myobj *)wmem_alloc(wmem_file_scope(), sizeof(myobj)) and replaces them with: wmem_new(wmem_file_scope(), myobj) to improve the readability of Wireshark's code. The replacement locations were identified with grep and replaced with the Python script below. grep command: egrep "wmem_alloc0?\(wmem_file_scope\(\), sizeof\([a-z_]+\)\)" . -R -l python script: import re import sys import fileinput pattern = r'\(([^\s]+) ?\*\) ?wmem_alloc(0?)\((wmem_[a-z]+_scope\(\)), sizeof\(\1\)\)' replacewith = r'wmem_new\2(\3, \1)' fname = sys.argv[1] for line in fileinput.input(fname, inplace=1, mode='rb'): output = re.sub(pattern, replacewith, line) sys.stdout.write(output) Change-Id: Ieac246c104bf01e32cbc6e11e53e81c7f639d870 Reviewed-on: https://code.wireshark.org/review/37158 Petri-Dish: Pascal Quantin Tested-by: Petri Dish Buildbot Reviewed-by: Pascal Quantin --- epan/dissectors/packet-mtp2.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'epan/dissectors/packet-mtp2.c') diff --git a/epan/dissectors/packet-mtp2.c b/epan/dissectors/packet-mtp2.c index edc6f87bcc..794f832fff 100644 --- a/epan/dissectors/packet-mtp2.c +++ b/epan/dissectors/packet-mtp2.c @@ -560,7 +560,7 @@ new_byte(char full_byte, guint8 **data, guint8 *data_len) if ((*data_len) == 0) { /* if data was never stored in this buffer before */ - *data = (guint8 *)wmem_alloc(wmem_packet_scope(), sizeof(guint8)); + *data = wmem_new(wmem_packet_scope(), guint8); (**data) = full_byte; (*data_len)++; } else { @@ -629,7 +629,7 @@ prepare_data_for_found_packet(tvbuff_t *tvb, guint8 unalignment_offset) { mtp2_recognized_packet_t *packet; - packet = (mtp2_recognized_packet_t *)wmem_alloc(wmem_packet_scope(), sizeof(mtp2_recognized_packet_t)); + packet = wmem_new(wmem_packet_scope(), mtp2_recognized_packet_t); /* store values */ packet->data = tvb; packet->unalignment_offset = unalignment_offset; @@ -663,7 +663,7 @@ dissect_mtp2_tvb(tvbuff_t* tvb, mtp2_mtp2_flag_search_t back_mtp2_flag_search, g mtp2_dissect_tvb_res_t *result = NULL; /* the result structure */ /* initialize the result structure, this will be returned at the end */ - result = (mtp2_dissect_tvb_res_t *)wmem_alloc(wmem_packet_scope(), sizeof(mtp2_dissect_tvb_res_t)); + result = wmem_new(wmem_packet_scope(), mtp2_dissect_tvb_res_t); result->mtp2_remain_data.before_first_flag = NULL; result->mtp2_remain_data.before_fh_unalignment_offset = 0; result->mtp2_remain_data.before_fh_frame_reset = FALSE; @@ -953,13 +953,13 @@ dissect_mtp2_bitstream(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void /* there is no proto data in the conversation */ if (conversation_get_proto_data(conversation, proto_mtp2) == NULL) { /* create a new convo data and fill it with initial data */ - convo_data = (mtp2_convo_data_t *) wmem_alloc(wmem_file_scope(), sizeof(mtp2_convo_data_t)); + convo_data = wmem_new(wmem_file_scope(), mtp2_convo_data_t); copy_address_wmem(wmem_file_scope(), &convo_data->addr_a, &pinfo->src); copy_address_wmem(wmem_file_scope(), &convo_data->addr_b, &pinfo->dst); convo_data->port_a = pinfo->srcport; convo_data->port_b = pinfo->destport; - convo_data->forward = (mtp2_convo_data_prev_packet_t *) wmem_alloc(wmem_file_scope(), sizeof(mtp2_convo_data_prev_packet_t)); - convo_data->backward = (mtp2_convo_data_prev_packet_t *) wmem_alloc(wmem_file_scope(), sizeof(mtp2_convo_data_prev_packet_t)); + convo_data->forward = wmem_new(wmem_file_scope(), mtp2_convo_data_prev_packet_t); + convo_data->backward = wmem_new(wmem_file_scope(), mtp2_convo_data_prev_packet_t); convo_data->forward->mtp2_flag_search.set = convo_data->backward->mtp2_flag_search.set= FALSE; convo_data->forward->mtp2_flag_search.mtp2_flag_search = convo_data->backward->mtp2_flag_search.mtp2_flag_search = 0x00; convo_data->forward->data_buff = convo_data->backward->data_buff = 0x00; @@ -983,7 +983,7 @@ dissect_mtp2_bitstream(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void /* if there is no per packet data -> create it */ if (mtp2_ppd == NULL) { - mtp2_ppd = (mtp2_ppd_t *) wmem_alloc(wmem_file_scope(), sizeof(mtp2_ppd_t)); + mtp2_ppd = wmem_new(wmem_file_scope(), mtp2_ppd_t); /* set the the proto_data_fields * because these are the values which we would like to see * if this packet is seen again */ -- cgit v1.2.3