Fix some cppcheck issues

This commit is contained in:
Martin Mathieson 2022-11-18 10:07:57 +00:00 committed by AndersBroman
parent d7ae26bf6c
commit 709d65883f
13 changed files with 42 additions and 50 deletions

View File

@ -4564,7 +4564,8 @@ static gint dissect_gatt_uuid(proto_tree *tree, packet_info *pinfo, tvbuff_t *tv
if (tvb_reported_length_remaining(tvb, offset) == 2) {
proto_tree_add_item(tree, hf_btatt_uuid16, tvb, offset, 2, ENC_LITTLE_ENDIAN);
sub_uuid = get_bluetooth_uuid(tvb, offset, 2);
/* TODO: want to do this and show? */
/* sub_uuid = get_bluetooth_uuid(tvb, offset, 2); */
offset += 2;
} else if (tvb_reported_length_remaining(tvb, offset) == 16) {
sub_item = proto_tree_add_item(tree, hf_btatt_uuid128, tvb, offset, 16, ENC_NA);
@ -10900,7 +10901,7 @@ get_value(packet_info *pinfo, guint32 handle, bluetooth_data_t *bluetooth_data,
sub_wmemtree = (wmem_tree_t *) wmem_tree_lookup32_array(fragments, key);
while (1) {
fragment_data = (sub_wmemtree) ? (fragment_data_t *) wmem_tree_lookup32_le(sub_wmemtree, frame_number) : NULL;
if (!fragment_data || (fragment_data && fragment_data->offset >= last_offset))
if (!fragment_data || (fragment_data->offset >= last_offset))
break;
if (first) {

View File

@ -6254,8 +6254,7 @@ static void dissect_ulsch_or_dlsch(tvbuff_t *tvb, packet_info *pinfo, proto_tree
/* Was this a Msg3 that led to a CR answer? */
if (PINFO_FD_VISITED(pinfo)) {
if ((p_mac_lte_info->direction == DIRECTION_UPLINK) &&
(number_of_headers >= 1) &&
(lcids[0] == 0)) {
(lcids[0] == 0)) /* N.B. there has to be at least 1 lcid if we got here */ {
guint32 cr_frame = GPOINTER_TO_UINT (g_hash_table_lookup(mac_lte_msg3_cr_hash,
GUINT_TO_POINTER(pinfo->num)));

View File

@ -1009,8 +1009,7 @@ mp2t_process_fragmented_payload(tvbuff_t *tvb, gint offset, guint remaining_len,
}
/* Check for full packets within this TS frame */
if (frag_tot_len &&
frag_tot_len <= remaining_len) {
if (frag_tot_len <= remaining_len) {
next_tvb = tvb_new_subset_length(tvb, offset, frag_tot_len);
mp2t_dissect_packet(next_tvb, pid_analysis->pload_type, pinfo, tree);
remaining_len -= frag_tot_len;
@ -1403,10 +1402,8 @@ dissect_tsp(tvbuff_t *tvb, gint offset, packet_info *pinfo,
if (pid_analysis->pload_type == pid_pload_docsis && (afc != 1)) {
/* DOCSIS packets should not have an adaptation field */
if (afc != 1) {
expert_add_info_format(pinfo, afci, &ei_mp2t_invalid_afc,
"Adaptation Field Control for DOCSIS packets must be 0x01");
}
expert_add_info_format(pinfo, afci, &ei_mp2t_invalid_afc,
"Adaptation Field Control for DOCSIS packets must be 0x01");
}
if (pid_analysis->pload_type == pid_pload_null) {

View File

@ -277,7 +277,7 @@ static int dissect_olsr_hello(tvbuff_t *tvb, packet_info *pinfo, proto_tree *ols
proto_item *ti;
proto_tree *link_type_tree;
guint16 message_size = 0;
guint16 message_size;
if (message_end - offset < 4) {
proto_tree_add_expert_format(olsr_tree, pinfo, &ei_olsr_not_enough_bytes, tvb, offset, message_end - offset,

View File

@ -5224,7 +5224,7 @@ dissect_pppmux(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _
static guint16 pid;
tvbuff_t *next_tvb;
int offset = 0, length_remaining;
int length_field = 0, pid_field = 0, hdr_length = 0;
int length_field, pid_field, hdr_length;
static int * const subframe_flags[] = {
&hf_pppmux_flags_pid,
&hf_pppmux_flags_field_length,
@ -5990,12 +5990,10 @@ dissect_ppp_raw_hdlc( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void*
col_set_str(pinfo->cinfo, COL_INFO, "PPP Fragment");
length = offset;
proto_tree_add_item(bs_tree, hf_ppp_hdlc_fragment, tvb, 0, length, ENC_NA);
if (length != 0) {
ppp_tvb = remove_escape_chars(tvb, pinfo, 0, length - 1);
if (ppp_tvb != NULL) {
add_new_data_source(pinfo, ppp_tvb, "PPP Fragment");
call_data_dissector(ppp_tvb, pinfo, tree);
}
ppp_tvb = remove_escape_chars(tvb, pinfo, 0, length - 1);
if (ppp_tvb != NULL) {
add_new_data_source(pinfo, ppp_tvb, "PPP Fragment");
call_data_dissector(ppp_tvb, pinfo, tree);
}
}
while (tvb_reported_length_remaining(tvb, offset) > 0) {

View File

@ -2123,33 +2123,32 @@ dissect_ptp_v1(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
hf_ptp_controlfield, tvb, PTP_CONTROLFIELD_OFFSET, 1, ENC_BIG_ENDIAN);
/* Subtree for the flag-field */
if(tree){
flags_ti = proto_tree_add_item(ptp_tree,
hf_ptp_flags, tvb, PTP_FLAGS_OFFSET, 2, ENC_BIG_ENDIAN);
/* TODO: use proto_tree_add_bitmask_list() ? */
flags_ti = proto_tree_add_item(ptp_tree,
hf_ptp_flags, tvb, PTP_FLAGS_OFFSET, 2, ENC_BIG_ENDIAN);
ptp_flags_tree = proto_item_add_subtree(flags_ti, ett_ptp_flags);
ptp_flags_tree = proto_item_add_subtree(flags_ti, ett_ptp_flags);
proto_tree_add_item(ptp_flags_tree,
hf_ptp_flags_li61, tvb, PTP_FLAGS_LI61_OFFSET, 2, ENC_BIG_ENDIAN);
proto_tree_add_item(ptp_flags_tree,
hf_ptp_flags_li61, tvb, PTP_FLAGS_LI61_OFFSET, 2, ENC_BIG_ENDIAN);
proto_tree_add_item(ptp_flags_tree,
hf_ptp_flags_li59, tvb, PTP_FLAGS_LI59_OFFSET, 2, ENC_BIG_ENDIAN);
proto_tree_add_item(ptp_flags_tree,
hf_ptp_flags_li59, tvb, PTP_FLAGS_LI59_OFFSET, 2, ENC_BIG_ENDIAN);
proto_tree_add_item(ptp_flags_tree,
hf_ptp_flags_boundary_clock, tvb, PTP_FLAGS_BOUNDARY_CLOCK_OFFSET, 2, ENC_BIG_ENDIAN);
proto_tree_add_item(ptp_flags_tree,
hf_ptp_flags_boundary_clock, tvb, PTP_FLAGS_BOUNDARY_CLOCK_OFFSET, 2, ENC_BIG_ENDIAN);
proto_tree_add_item(ptp_flags_tree,
hf_ptp_flags_assist, tvb, PTP_FLAGS_ASSIST_OFFSET, 2, ENC_BIG_ENDIAN);
proto_tree_add_item(ptp_flags_tree,
hf_ptp_flags_assist, tvb, PTP_FLAGS_ASSIST_OFFSET, 2, ENC_BIG_ENDIAN);
proto_tree_add_item(ptp_flags_tree,
hf_ptp_flags_ext_sync, tvb, PTP_FLAGS_EXT_SYNC_OFFSET, 2, ENC_BIG_ENDIAN);
proto_tree_add_item(ptp_flags_tree,
hf_ptp_flags_ext_sync, tvb, PTP_FLAGS_EXT_SYNC_OFFSET, 2, ENC_BIG_ENDIAN);
proto_tree_add_item(ptp_flags_tree,
hf_ptp_flags_parent, tvb, PTP_FLAGS_PARENT_STATS_OFFSET, 2, ENC_BIG_ENDIAN);
proto_tree_add_item(ptp_flags_tree,
hf_ptp_flags_parent, tvb, PTP_FLAGS_PARENT_STATS_OFFSET, 2, ENC_BIG_ENDIAN);
proto_tree_add_item(ptp_flags_tree,
hf_ptp_flags_sync_burst, tvb, PTP_FLAGS_SYNC_BURST_OFFSET, 2, ENC_BIG_ENDIAN);
}
proto_tree_add_item(ptp_flags_tree,
hf_ptp_flags_sync_burst, tvb, PTP_FLAGS_SYNC_BURST_OFFSET, 2, ENC_BIG_ENDIAN);
/* The rest of the ptp-dissector depends on the control-field */
@ -2979,7 +2978,7 @@ dissect_ptp_v2(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gboolean ptp
/* now take only 1/2 of it */
frame_info->pdelay.mean_propagation_delay_unscaled.nsecs /= 2;
if (frame_info->pdelay.mean_propagation_delay_unscaled.secs % 1 == 1) {
if ((frame_info->pdelay.mean_propagation_delay_unscaled.secs % 2) == 1) {
frame_info->pdelay.mean_propagation_delay_unscaled.secs -= 1;
frame_info->pdelay.mean_propagation_delay_unscaled.nsecs += NS_PER_S / 2;
}

View File

@ -672,7 +672,6 @@ static void dissect_rlc_nr_um(tvbuff_t *tvb, packet_info *pinfo,
proto_item *um_ti;
proto_tree *um_header_tree;
proto_item *um_header_ti;
gboolean is_truncated = FALSE;
proto_item *truncated_ti;
proto_item *reserved_ti;
int start_offset = offset;
@ -736,7 +735,7 @@ static void dissect_rlc_nr_um(tvbuff_t *tvb, packet_info *pinfo,
if (global_rlc_nr_headers_expected) {
/* There might not be any data, if only headers (plus control data) were logged */
is_truncated = (tvb_captured_length_remaining(tvb, offset) == 0);
gboolean is_truncated = (tvb_captured_length_remaining(tvb, offset) == 0);
truncated_ti = proto_tree_add_boolean(tree, hf_rlc_nr_header_only, tvb, 0, 0,
is_truncated);
if (is_truncated) {
@ -1003,7 +1002,6 @@ static void dissect_rlc_nr_am(tvbuff_t *tvb, packet_info *pinfo,
proto_tree *am_header_tree;
proto_item *am_header_ti;
gint start_offset = offset;
gboolean is_truncated = FALSE;
proto_item *truncated_ti;
proto_item *reserved_ti;
guint32 so = 0;
@ -1089,7 +1087,7 @@ static void dissect_rlc_nr_am(tvbuff_t *tvb, packet_info *pinfo,
/* There might not be any data, if only headers (plus control data) were logged */
if (global_rlc_nr_headers_expected) {
is_truncated = (tvb_captured_length_remaining(tvb, offset) == 0);
gboolean is_truncated = (tvb_captured_length_remaining(tvb, offset) == 0);
truncated_ti = proto_tree_add_boolean(tree, hf_rlc_nr_header_only, tvb, 0, 0,
is_truncated);
if (is_truncated) {

View File

@ -484,7 +484,7 @@ static void
rtpproxy_add_notify_addr(tvbuff_t *tvb, packet_info *pinfo, proto_tree *rtpproxy_tree, guint begin, guint end)
{
gint offset = 0;
gint tmp = 0;
gint tmp;
gboolean ipv6 = FALSE;
guint32 ipaddr[4]; /* Enough room for IPv4 or IPv6 */

View File

@ -2764,8 +2764,8 @@ dissect_pipe_lanman(tvbuff_t *pd_tvb, tvbuff_t *p_tvb, tvbuff_t *d_tvb,
/* ok we have seen this one before */
/* if it looks like an interim response, update COL_INFO and return */
if( ( (p_tvb==NULL) || (tvb_reported_length(p_tvb)==0) )
&& ( (d_tvb==NULL) || (tvb_reported_length(d_tvb)==0) ) ){
if( ( tvb_reported_length(p_tvb)==0 )
&& ( tvb_reported_length(d_tvb)==0 ) ){
/* command */
col_add_fstr(pinfo->cinfo, COL_INFO, "%s Interim Response",
val_to_str_ext(trp->lanman_cmd, &commands_ext, "Unknown Command (%u)"));

View File

@ -640,7 +640,7 @@ static int dissect_context(tvbuff_t *tvb, proto_tree *tree, int offset)
static int dissect_context_as_cif(tvbuff_t *tvb, proto_tree *tree, int offset, uint32_t cif,
complex_dissector_t *complex_fptr, int **item_ptr, const int *size_ptr, int stop) {
for (int i = 31; i > stop; i--) {
if (cif & (1 << i)) {
if (cif & (1u << i)) {
if (complex_fptr[i] != NULL) {
// a complex dissector returns the variable part of field length (in bytes)
offset += (*complex_fptr[i])(tree, tvb, offset);

View File

@ -9179,7 +9179,7 @@ add_aura_mask(ptvcursor_t* ptv) {
ptvcursor_add_ret_uint(ptv, hf_woww_aura_mask, 4, ENC_LITTLE_ENDIAN, &mask);
for (gint i = 0; i < 32; ++i) {
if (mask & (1 << i)) {
if (mask & (1u << i)) {
ptvcursor_add(ptv, hf_woww_aura, 4, ENC_LITTLE_ENDIAN);
}
}
@ -9197,7 +9197,7 @@ add_update_mask(ptvcursor_t* ptv) {
for (guint32 mask = 0; mask < amount_of_masks; ++mask) {
for (guint32 i = 0; i < 32; ++i) {
if (masks[mask] & (1 << i)) {
if (masks[mask] & (1u << i)) {
ptvcursor_add(ptv, hf_woww_update_mask_value, 4, ENC_LITTLE_ENDIAN);
}
}

View File

@ -9583,7 +9583,7 @@ proto_item_fill_label(field_info *fi, gchar *label_str)
static void
fill_label_boolean(field_info *fi, gchar *label_str)
{
char *p = label_str;
char *p;
int bitfield_byte_length = 0, bitwidth;
guint64 unshifted_value;
guint64 value;

View File

@ -224,7 +224,7 @@ static int dissect_opcua_message(tvbuff_t *tvb, packet_info *pinfo, proto_tree *
guint8 chunkType = 0;
guint32 opcua_seqid = 0;
guint32 opcua_num = 0;
guint32 opcua_seqnum = 0;
guint32 opcua_seqnum;
fragment_head *frag_msg = NULL;
fragment_item *frag_i = NULL;