aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDario Lombardo <lomato@gmail.com>2020-04-13 23:39:32 +0200
committerAnders Broman <a.broman58@gmail.com>2020-04-14 06:23:00 +0000
commitc2d67c0928ed222f6f984b0cf09985fd8e1c6232 (patch)
tree70f63968d10713b2cdcaf5bd000e9dce8eb3f7d4
parent9eeb1c80fb3b03127ad781a6471462db414d6d91 (diff)
wiretap: don't use memset where possible.
Change-Id: Id74764242ba13fb4ed58299a475096a64e5c6b5b Reviewed-on: https://code.wireshark.org/review/36838 Petri-Dish: Anders Broman <a.broman58@gmail.com> Tested-by: Petri Dish Buildbot Reviewed-by: Anders Broman <a.broman58@gmail.com>
-rw-r--r--wiretap/busmaster.c12
-rw-r--r--wiretap/candump.c9
-rw-r--r--wiretap/catapult_dct2000.c3
-rw-r--r--wiretap/commview.c4
-rw-r--r--wiretap/erf.c15
-rw-r--r--wiretap/nettrace_3gpp_32_423.c4
-rw-r--r--wiretap/pcapng.c3
-rw-r--r--wiretap/peektagged.c3
-rw-r--r--wiretap/visual.c9
9 files changed, 18 insertions, 44 deletions
diff --git a/wiretap/busmaster.c b/wiretap/busmaster.c
index 60b7849715..8dee4ed6dd 100644
--- a/wiretap/busmaster.c
+++ b/wiretap/busmaster.c
@@ -86,9 +86,8 @@ busmaster_gen_packet(wtap_rec *rec, Buffer *buf,
if (is_fd)
{
- canfd_frame_t canfd_frame;
+ canfd_frame_t canfd_frame = {0};
- memset(&canfd_frame, 0, sizeof(canfd_frame));
canfd_frame.can_id = (msg->id & (is_eff ? CAN_EFF_MASK : CAN_SFF_MASK)) |
(is_eff ? CAN_EFF_FLAG : 0) |
(is_err ? CAN_ERR_FLAG : 0);
@@ -105,9 +104,8 @@ busmaster_gen_packet(wtap_rec *rec, Buffer *buf,
}
else
{
- can_frame_t can_frame;
+ can_frame_t can_frame = {0};
- memset(&can_frame, 0, sizeof(can_frame));
can_frame.can_id = (msg->id & (is_eff ? CAN_EFF_MASK : CAN_SFF_MASK)) |
(is_rtr ? CAN_RTR_FLAG : 0) |
(is_eff ? CAN_EFF_FLAG : 0) |
@@ -225,7 +223,7 @@ busmaster_parse(FILE_T fh, busmaster_state_t *state, int *err, char **err_info)
wtap_open_return_val
busmaster_open(wtap *wth, int *err, char **err_info)
{
- busmaster_state_t state;
+ busmaster_state_t state = {0};
log_entry_type_t entry;
busmaster_debug_printf("%s: Trying to open with busmaster log reader\n",
@@ -235,7 +233,6 @@ busmaster_open(wtap *wth, int *err, char **err_info)
if (file_seek(wth->fh, 0, SEEK_SET, err) == -1)
return WTAP_OPEN_ERROR;
- memset(&state, 0, sizeof(state));
entry = busmaster_parse(wth->fh, &state, err, err_info);
g_free(*err_info);
@@ -398,7 +395,7 @@ busmaster_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec,
Buffer *buf, int *err, gchar **err_info)
{
busmaster_priv_t *priv_entry;
- busmaster_state_t state;
+ busmaster_state_t state = {0};
log_entry_type_t entry;
busmaster_debug_printf("%s: offset = %" PRIi64 "\n", G_STRFUNC, seek_off);
@@ -415,7 +412,6 @@ busmaster_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec,
if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
return FALSE;
- memset(&state, 0, sizeof(state));
state.header = *priv_entry;
entry = busmaster_parse(wth->random_fh, &state, err, err_info);
diff --git a/wiretap/candump.c b/wiretap/candump.c
index 3eb17dd2c2..0def7bcb50 100644
--- a/wiretap/candump.c
+++ b/wiretap/candump.c
@@ -57,9 +57,8 @@ candump_write_packet(wtap_rec *rec, Buffer *buf, const msg_t *msg)
if (msg->is_fd)
{
- canfd_frame_t canfd_frame;
+ canfd_frame_t canfd_frame = {0};
- memset(&canfd_frame, 0, sizeof(canfd_frame));
canfd_frame.can_id = msg->id;
canfd_frame.flags = msg->flags;
canfd_frame.len = msg->data.length;
@@ -69,9 +68,8 @@ candump_write_packet(wtap_rec *rec, Buffer *buf, const msg_t *msg)
}
else
{
- can_frame_t can_frame;
+ can_frame_t can_frame = {0};
- memset(&can_frame, 0, sizeof(can_frame));
can_frame.can_id = msg->id;
can_frame.can_dlc = msg->data.length;
memcpy(can_frame.data, msg->data.data, msg->data.length);
@@ -91,7 +89,7 @@ candump_write_packet(wtap_rec *rec, Buffer *buf, const msg_t *msg)
static gboolean
candump_parse(FILE_T fh, msg_t *msg, gint64 *offset, int *err, char **err_info)
{
- candump_state_t state;
+ candump_state_t state = {0};
gboolean ok;
gint64 seek_off;
@@ -99,7 +97,6 @@ candump_parse(FILE_T fh, msg_t *msg, gint64 *offset, int *err, char **err_info)
ws_debug_printf("%s: Trying candump file decoder\n", G_STRFUNC);
#endif
- memset(&state, 0, sizeof(state));
state.fh = fh;
do
diff --git a/wiretap/catapult_dct2000.c b/wiretap/catapult_dct2000.c
index 1f339e24e5..60da686174 100644
--- a/wiretap/catapult_dct2000.c
+++ b/wiretap/catapult_dct2000.c
@@ -198,8 +198,7 @@ catapult_dct2000_open(wtap *wth, int *err, gchar **err_info)
/* Need entry in file_externals table */
/* Allocate a new file_externals structure for this file */
- file_externals = g_new(dct2000_file_externals_t,1);
- memset((void*)file_externals, '\0', sizeof(dct2000_file_externals_t));
+ file_externals = g_new0(dct2000_file_externals_t, 1);
/* Copy this first line into buffer so could write out later */
g_strlcpy(file_externals->firstline, linebuff, firstline_length+1);
diff --git a/wiretap/commview.c b/wiretap/commview.c
index ce5f68f42e..7b93d2792c 100644
--- a/wiretap/commview.c
+++ b/wiretap/commview.c
@@ -391,7 +391,7 @@ static gboolean commview_dump(wtap_dumper *wdh,
const wtap_rec *rec,
const guint8 *pd, int *err, gchar **err_info _U_)
{
- commview_header_t cv_hdr;
+ commview_header_t cv_hdr = {0};
struct tm *tm;
/* We can only write packet records. */
@@ -408,8 +408,6 @@ static gboolean commview_dump(wtap_dumper *wdh,
return FALSE;
}
- memset(&cv_hdr, 0, sizeof(cv_hdr));
-
cv_hdr.data_len = GUINT16_TO_LE((guint16)rec->rec_header.packet_header.caplen);
cv_hdr.source_data_len = GUINT16_TO_LE((guint16)rec->rec_header.packet_header.caplen);
cv_hdr.version = 0;
diff --git a/wiretap/erf.c b/wiretap/erf.c
index 4ae82a0e3c..6f68b03577 100644
--- a/wiretap/erf.c
+++ b/wiretap/erf.c
@@ -2733,12 +2733,10 @@ static int populate_interface_info(erf_t *erf_priv, wtap *wth, union wtap_pseudo
int interface_index = -1;
wtap_block_t int_data = NULL;
wtapng_if_descr_mandatory_t* int_data_mand = NULL;
- wtapng_if_descr_filter_t if_filter;
+ wtapng_if_descr_filter_t if_filter = {0};
guint32 if_num = 0;
struct erf_if_info* if_info = NULL;
- memset(&if_filter, 0, sizeof(if_filter));
-
if (!wth || !state || !pseudo_header || !state->if_map)
return -1;
@@ -2926,15 +2924,13 @@ static int populate_stream_info(erf_t *erf_priv _U_, wtap *wth, union wtap_pseud
int interface_index = -1;
wtap_block_t int_data = NULL;
wtapng_if_descr_mandatory_t* int_data_mand = NULL;
- wtapng_if_descr_filter_t if_filter;
+ wtapng_if_descr_filter_t if_filter = {0};
guint32 if_num = 0;
gint32 stream_num = -1;
guint8 *tag_ptr_tmp;
guint32 remaining_len_tmp;
struct erf_if_info* if_info = NULL;
- memset(&if_filter, 0, sizeof(if_filter));
-
if (!wth || !pseudo_header || !state || !state->if_map)
return -1;
@@ -3124,7 +3120,7 @@ static int populate_anchor_info(erf_t *erf_priv, wtap *wth, union wtap_pseudo_he
/* Populates the capture and interface information for display on the Capture File Properties */
static int populate_summary_info(erf_t *erf_priv, wtap *wth, union wtap_pseudo_header *pseudo_header, Buffer *buf, guint32 packet_size, GPtrArray *anchor_mappings_to_update)
{
- struct erf_meta_read_state state;
+ struct erf_meta_read_state state = {0};
struct erf_meta_read_state *state_post = NULL;
guint64 host_id;
guint8 source_id;
@@ -3137,8 +3133,6 @@ static int populate_summary_info(erf_t *erf_priv, wtap *wth, union wtap_pseudo_h
if (!erf_priv || !wth || !pseudo_header)
return -1;
- memset(&state, 0, sizeof(struct erf_meta_read_state));
-
erf_get_source_from_header(pseudo_header, &host_id, &source_id);
if (host_id == 0) {
@@ -3335,14 +3329,13 @@ static gboolean get_user_comment_string(wtap_dumper *wdh, gchar** user_comment_p
}
static gboolean erf_dump_priv_compare_capture_comment(wtap_dumper *wdh _U_, erf_dump_t *dump_priv, const union wtap_pseudo_header *pseudo_header, const guint8 *pd){
- struct erf_meta_read_state state;
+ struct erf_meta_read_state state = {0};
struct erf_meta_tag tag = {0, 0, NULL};
guint32 tagtotallength;
gboolean found_capture_section = FALSE;
gboolean found_normal_section = FALSE;
gchar* comment_ptr = NULL;
- memset(&state, 0, sizeof(struct erf_meta_read_state));
state.remaining_len = pseudo_header->erf.phdr.wlen;
memcpy(&(state.tag_ptr), &pd, sizeof(pd));
diff --git a/wiretap/nettrace_3gpp_32_423.c b/wiretap/nettrace_3gpp_32_423.c
index 2965fd05b3..b106774af6 100644
--- a/wiretap/nettrace_3gpp_32_423.c
+++ b/wiretap/nettrace_3gpp_32_423.c
@@ -845,9 +845,7 @@ create_temp_pcapng_file(wtap *wth, int *err, gchar **err_info, nettrace_3gpp_32_
gsize opt_len;
gchar *opt_str;
/* Info to build exported_pdu tags*/
- exported_pdu_info_t exported_pdu_info;
-
- memset(&exported_pdu_info, 0x0, sizeof(exported_pdu_info_t));
+ exported_pdu_info_t exported_pdu_info = {0};
import_file_fd = create_tempfile(&(file_info->tmpname), "Wireshark_PDU_", NULL, NULL);
if (import_file_fd < 0)
diff --git a/wiretap/pcapng.c b/wiretap/pcapng.c
index 2f1a9ee2fe..1cd7311318 100644
--- a/wiretap/pcapng.c
+++ b/wiretap/pcapng.c
@@ -916,8 +916,7 @@ pcapng_read_if_descr_block(wtap *wth, FILE_T fh, pcapng_block_header_t *bh,
*/
case(OPT_IDB_FILTER): /* if_filter */
if (oh.option_length > 0 && oh.option_length < opt_cont_buf_len) {
- wtapng_if_descr_filter_t if_filter;
- memset(&if_filter, 0, sizeof(if_filter));
+ wtapng_if_descr_filter_t if_filter = {0};
/* The first byte of the Option Data keeps a code of the filter used (e.g. if this is a libpcap string,
* or BPF bytecode.
diff --git a/wiretap/peektagged.c b/wiretap/peektagged.c
index b0467f06fc..6a7f8bddb3 100644
--- a/wiretap/peektagged.c
+++ b/wiretap/peektagged.c
@@ -427,14 +427,13 @@ peektagged_read_packet(wtap *wth, FILE_T fh, wtap_rec *rec,
guint32 data_rate_or_mcs_index = 0;
gint channel;
guint frequency;
- struct ieee_802_11_phdr ieee_802_11;
+ struct ieee_802_11_phdr ieee_802_11 = {0};
guint i;
int skip_len = 0;
guint64 t;
timestamp.upper = 0;
timestamp.lower = 0;
- memset(&ieee_802_11, 0, sizeof ieee_802_11);
ieee_802_11.fcs_len = -1; /* Unknown */
ieee_802_11.decrypted = FALSE;
ieee_802_11.datapad = FALSE;
diff --git a/wiretap/visual.c b/wiretap/visual.c
index 1c5e9aac8b..c3d80ad255 100644
--- a/wiretap/visual.c
+++ b/wiretap/visual.c
@@ -627,7 +627,7 @@ static gboolean visual_dump(wtap_dumper *wdh, const wtap_rec *rec,
{
const union wtap_pseudo_header *pseudo_header = &rec->rec_header.packet_header.pseudo_header;
struct visual_write_info * visual = (struct visual_write_info *)wdh->priv;
- struct visual_pkt_hdr vpkt_hdr;
+ struct visual_pkt_hdr vpkt_hdr = {0};
size_t hdr_size = sizeof vpkt_hdr;
guint delta_msec;
guint32 packet_status;
@@ -658,9 +658,6 @@ static gboolean visual_dump(wtap_dumper *wdh, const wtap_rec *rec,
if (visual == 0)
return FALSE;
- /* Zero out unused and reserved fields in the packet header. */
- memset(&vpkt_hdr, 0, hdr_size);
-
/* Visual UpTime capture files have a capture start time in the
file header. Each packet has a capture time (in msec) relative
to the file start time. Use the time of the first packet as the
@@ -760,7 +757,7 @@ static gboolean visual_dump_finish(wtap_dumper *wdh, int *err)
{
struct visual_write_info * visual = (struct visual_write_info *)wdh->priv;
size_t n_to_write;
- struct visual_file_hdr vfile_hdr;
+ struct visual_file_hdr vfile_hdr = {0};
const char *magicp;
size_t magic_size;
@@ -792,8 +789,6 @@ static gboolean visual_dump_finish(wtap_dumper *wdh, int *err)
return FALSE;
}
- /* Initialize the file header with zeroes for the reserved fields. */
- memset(&vfile_hdr, '\0', sizeof vfile_hdr);
vfile_hdr.num_pkts = GUINT32_TO_LE(visual->index_table_index);
vfile_hdr.start_time = GUINT32_TO_LE(visual->start_time);
vfile_hdr.max_length = GUINT16_TO_LE(65535);