Fix more unused variables and enable unused-but-set-variable errors.

Add -Werror=unused-but-set-variable to our default compiler flags and fix

```
epan/dissectors/packet-dcerpc-frsrpc.c:709:10: error: variable 'nb_chunk' set but not used [-Werror,-Wunused-but-set-variable]
        guint32 nb_chunk = 0;
                ^
```

```
epan/dissectors/packet-dcom-oxid.c:175:13: error: variable 'u32ItemIdx' set but not used [-Werror,-Wunused-but-set-variable]
    guint32 u32ItemIdx;
            ^
```

```
epan/dissectors/packet-l2tp.c:1775:104: error: parameter 'ccid' set but not used [-Werror,-Wunused-but-set-parameter]
static int dissect_l2tp_ericsson_avps(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, guint32 ccid)
                                                                                                       ^
```

```
epan/dissectors/packet-ldp.c:1922:19: error: variable 'ix' set but not used [-Werror,-Wunused-but-set-variable]
    guint8        ix;
                  ^
```

```
epan/dissectors/packet-nas_5gs.c:4757:14: error: variable 'curr_len' set but not used [-Werror,-Wunused-but-set-variable]
    guint i, curr_len;
             ^
```

```
epan/dissectors/packet-per.c:1769:6: error: variable 'extension_addition_entries' set but not used [-Werror,-Wunused-but-set-variable]
        int extension_addition_entries;
            ^
```

```
epan/dissectors/packet-rtitcp.c:618:11: error: variable 'messages_count' set but not used [-Werror,-Wunused-but-set-variable]
    guint messages_count, offset;
          ^
```

```
epan/dissectors/packet-tcp.c:2130:9: error: variable 'ackcount' set but not used [-Werror,-Wunused-but-set-variable]
    int ackcount;
        ^
epan/dissectors/packet-tcp.c:3317:12: error: variable 'nbOptionsChanged' set but not used [-Werror,-Wunused-but-set-variable]
    guint8 nbOptionsChanged = 0;
           ^
```

```
epan/dissectors/packet-zbee-zcl-se.c:11802:15: error: variable 'i' set but not used [-Werror,-Wunused-but-set-variable]
    for (gint i = 0; tvb_reported_length_remaining(tvb, *offset) >= 5; i++) {
              ^
```

```
ui/iface_lists.c:142:23: error: variable 'linktype_count' set but not used [-Werror,-Wunused-but-set-variable]
    gint              linktype_count;
                      ^
```

```
ui/voip_calls.c:456:15: error: variable 'item_num' set but not used [-Werror,-Wunused-but-set-variable]
    guint     item_num;
              ^
```

```
file.c:572:17: error: variable 'count' set but not used [-Werror,-Wunused-but-set-variable]
        guint32 count             = 0;
                ^
```

```
file.c:3667:24: warning: cast from 'const unsigned char *' to 'unsigned char *' drops const qualifier [-Wcast-qual]
        pd = (guint8 *)ws_mempbrk_exec(pd, buf_end - pd, pattern, &c_char);
                       ^
```

```
ui/qt/io_graph_dialog.cpp:1932:60: error: variable 'mavg_right' set but not used [-Werror,-Wunused-but-set-variable]
    unsigned int mavg_in_average_count = 0, mavg_left = 0, mavg_right = 0;
                                                           ^
```

```
ui/qt/stats_tree_dialog.cpp:166:9: error: variable 'node_count' set but not used [-Werror,-Wunused-but-set-variable]
    int node_count = 0;
        ^
```

```
ui/qt/models/profile_model.cpp:1142:13: error: variable 'entryCount' set but not used [-Werror,-Wunused-but-set-variable]
        int entryCount = 0;
            ^
```
This commit is contained in:
Gerald Combs 2022-11-08 09:24:16 -08:00
parent b662f565f0
commit 85357ae721
16 changed files with 16 additions and 50 deletions

View File

@ -676,6 +676,12 @@ else() # ! MSVC
# code should not introduce new deprecations in any case.
#
-Wno-error=deprecated-declarations
#
# GCC < 6.0 had issues with false positives, but current versions
# and clang appear to be OK.
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66543
#
-Werror=unused-but-set-variable
)
#

View File

@ -663,7 +663,7 @@ frsrpc_dissect_struct_CommPktChunk(tvbuff_t *tvb _U_, int offset _U_, packet_inf
item = proto_tree_add_item(parent_tree, hf_index, tvb, offset, -1, TRUE);
tree = proto_item_add_subtree(item, ett_frsrpc_frsrpc_CommPktChunk);
}
offset = frsrpc_dissect_element_CommPktChunk_type(tvb, offset, pinfo, tree, di, drep, &type);
offset = frsrpc_dissect_element_CommPktChunk_data(tvb, offset, pinfo, tree, di, drep, &type);
for (i=0; frsrpc_frsrpc_CommPktChunkType_vals[i].strptr; i++) {
@ -706,14 +706,13 @@ frsrpc_dissect_enum_CommPktCommand(tvbuff_t *tvb _U_, int offset _U_, packet_inf
static int
frsrpc_dissect_struct_frsrpc_CommPktChunkCtr(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, dcerpc_info* di, guint8 *drep _U_, int hf_index, guint32 param _U_)
{
guint32 nb_chunk = 0;
guint32 remaining = tvb_reported_length_remaining(tvb, offset);
int align_status = di->no_align;
if (remaining > 0) {
proto_item *item = proto_tree_add_item(tree, hf_index, tvb, offset, -1, TRUE);
proto_tree *subtree = proto_item_add_subtree(item, ett_ChunkCtr);
di->no_align = 1;
for(nb_chunk = 0; remaining > 0; nb_chunk++) {
while (remaining > 0) {
offset = frsrpc_dissect_struct_CommPktChunk(tvb, offset, pinfo, subtree, di, drep, hf_CommPktChunk, param);
remaining = tvb_reported_length_remaining(tvb, offset);
}

View File

@ -172,7 +172,6 @@ dissect_oxid_resolve_oxid2_rqst(tvbuff_t *tvb, int offset,
{
guint16 u16ProtSeqs;
guint32 u32ArraySize;
guint32 u32ItemIdx;
offset = dissect_dcom_ID(tvb, offset, pinfo, tree, di, drep,
@ -184,11 +183,9 @@ dissect_oxid_resolve_oxid2_rqst(tvbuff_t *tvb, int offset,
offset = dissect_dcom_dcerpc_array_size(tvb, offset, pinfo, tree, di, drep,
&u32ArraySize);
u32ItemIdx = 1;
while (u32ArraySize--) {
offset = dissect_dcom_WORD(tvb, offset, pinfo, tree, di, drep,
hf_oxid_protseqs, &u16ProtSeqs);
u32ItemIdx++;
}
return offset;

View File

@ -1772,7 +1772,7 @@ static int dissect_l2tp_ericsson_tei_sc_map(tvbuff_t *tvb, proto_tree *parent_tr
return offset;
}
static int dissect_l2tp_ericsson_avps(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, guint32 ccid)
static int dissect_l2tp_ericsson_avps(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, guint32 ccid _U_)
{
int offset = 0;
int avp_type;
@ -1813,8 +1813,6 @@ static int dissect_l2tp_ericsson_avps(tvbuff_t *tvb, packet_info *pinfo _U_, pro
offset += 2;
avp_len -= 2;
ccid++;
switch (avp_type) {
case ERICSSON_MSG_TYPE:
proto_tree_add_item_ret_uint(l2tp_avp_tree, hf_l2tp_ericsson_msg_type, tvb, offset, 2, ENC_BIG_ENDIAN, &msg_type);

View File

@ -1919,11 +1919,10 @@ static void
dissect_tlv_mac(tvbuff_t *tvb, packet_info *pinfo, guint offset, proto_tree *tree, int rem)
{
proto_tree *val_tree;
guint8 ix;
val_tree=proto_tree_add_subtree(tree, tvb, offset, rem, ett_ldp_tlv_val, NULL, "MAC addresses");
for(ix=1; rem >= 6; ix++, offset += 6, rem -= 6) {
for(; rem >= 6; offset += 6, rem -= 6) {
proto_tree_add_item(val_tree, hf_ldp_tlv_mac, tvb, offset, 6, ENC_NA);
}
if (rem)

View File

@ -4754,9 +4754,8 @@ de_nas_5gs_sm_mapped_eps_b_cont(tvbuff_t *tvb, proto_tree *tree, packet_info *pi
proto_tree * sub_tree, *sub_tree1;
guint32 num_cont, length, opt_code, num_eps_parms, param_id;
proto_item * item;
guint i, curr_len;
guint i;
curr_len = len;
curr_offset = offset;
num_cont = 1;
@ -4785,12 +4784,10 @@ de_nas_5gs_sm_mapped_eps_b_cont(tvbuff_t *tvb, proto_tree *tree, packet_info *pi
/* EPS bearer identity */
proto_tree_add_item(sub_tree, hf_nas_5gs_sm_mapd_eps_b_cont_id, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
curr_offset++;
curr_len--;
/* Length of Mapped EPS bearer context*/
proto_tree_add_item_ret_uint(sub_tree, hf_nas_5gs_sm_length, tvb, curr_offset, 2, ENC_BIG_ENDIAN, &length);
curr_offset += 2;
curr_len -= 2;
/* 8 7 6 5 4 3 2 1 */
/* operation code | spare | E | number of EPS params */
@ -4810,7 +4807,6 @@ de_nas_5gs_sm_mapped_eps_b_cont(tvbuff_t *tvb, proto_tree *tree, packet_info *pi
}
curr_offset++;
curr_len--;
i = 1;
/* EPS parameters list */
@ -4823,12 +4819,10 @@ de_nas_5gs_sm_mapped_eps_b_cont(tvbuff_t *tvb, proto_tree *tree, packet_info *pi
proto_tree_add_item_ret_uint(sub_tree1, hf_nas_5gs_sm_mapd_eps_b_cont_param_id, tvb, curr_offset, 1, ENC_BIG_ENDIAN, &param_id);
proto_item_append_text(item, " - %s", val_to_str_const(param_id, nas_5gs_sm_mapd_eps_b_cont_param_id_vals, "Unknown"));
curr_offset++;
curr_len--;
/*length of the EPS parameter contents field */
proto_tree_add_item_ret_uint(sub_tree1, hf_nas_5gs_sm_length, tvb, curr_offset, 1, ENC_BIG_ENDIAN, &length);
curr_offset++;
curr_len--;
proto_item_set_len(item, length + 2);
/*content of the EPS parameter contents field */
@ -4858,7 +4852,6 @@ de_nas_5gs_sm_mapped_eps_b_cont(tvbuff_t *tvb, proto_tree *tree, packet_info *pi
break;
}
curr_offset +=length;
curr_len -= length;
i++;
num_eps_parms--;
}

View File

@ -1766,7 +1766,6 @@ dissect_per_choice(tvbuff_t *tvb, guint32 offset, asn1_ctx_t *actx, proto_tree *
{
gboolean /*extension_present,*/ extension_flag;
int extension_root_entries;
int extension_addition_entries;
guint32 choice_index;
int i, idx, cidx;
guint32 ext_length = 0;
@ -1790,7 +1789,6 @@ DEBUG_ENTRY("dissect_per_choice");
/* count the number of entries in the extension root and extension addition */
extension_root_entries = 0;
extension_addition_entries = 0;
for (i=0; choice[i].p_id; i++) {
switch(choice[i].extension){
case ASN1_NO_EXTENSIONS:
@ -1798,7 +1796,6 @@ DEBUG_ENTRY("dissect_per_choice");
extension_root_entries++;
break;
case ASN1_NOT_EXTENSION_ROOT:
extension_addition_entries++;
break;
}
}

View File

@ -615,19 +615,16 @@ static guint16 dissect_control_message(proto_tree *rtitcp_tree, tvbuff_t *tvb, p
/* This function dissects all the control messages found */
static guint dissect_rtitcp_control_protocol(proto_tree *rtitcp_tree, tvbuff_t *tvb, packet_info *pinfo) {
guint messages_count, offset;
guint offset;
guint16 msg_length;
guint32 tvb_len;
offset = 0;
tvb_len = tvb_reported_length(tvb);
messages_count = 0;
while (offset < tvb_len) {
msg_length = dissect_control_message(rtitcp_tree, tvb, pinfo, offset);
offset += msg_length;
++messages_count;
}
return offset;

View File

@ -2127,7 +2127,6 @@ tcp_analyze_sequence_number(packet_info *pinfo, guint32 seq, guint32 ack, guint3
tcp_unacked_t *ual=NULL;
tcp_unacked_t *prevual=NULL;
guint32 nextseq;
int ackcount;
#if 0
printf("\nanalyze_sequence numbers frame:%u\n",pinfo->num);
@ -2673,7 +2672,6 @@ finished_checking_retransmission_type:
/* remove all segments this ACKs and we don't need to keep around any more
*/
ackcount=0;
prevual = NULL;
ual = tcpd->rev->tcp_analyze_seq_info->segments;
while(ual) {
@ -2698,7 +2696,6 @@ finished_checking_retransmission_type:
}
/* This segment is old, or an exact match. Delete the segment from the list */
ackcount++;
tmpual=ual->next;
if (tcpd->rev->scps_capable) {
@ -3313,6 +3310,7 @@ mptcp_add_analysis_subtree(packet_info *pinfo, tvbuff_t *tvb, proto_tree *parent
proto_item_set_generated(item);
#if 0 // nbOptionsChanged is currently unused.
/* store the TCP Options related to MPTCP then we will avoid false DUP ACKs later */
guint8 nbOptionsChanged = 0;
if((tcpd->mptcp_analysis->mp_operations&(0x01))!=tcph->th_mptcp->mh_mpc) {
@ -3348,6 +3346,7 @@ mptcp_add_analysis_subtree(packet_info *pinfo, tvbuff_t *tvb, proto_tree *parent
nbOptionsChanged++;
}
/* we could track MPTCP option changes here, with nbOptionsChanged */
#endif
item = proto_tree_add_uint(tree, hf_mptcp_stream, tvb, 0, 0, mptcpd->stream);
proto_item_set_generated(item);

View File

@ -11799,7 +11799,7 @@ dissect_zcl_calendar_publish_seasons(tvbuff_t *tvb, proto_tree *tree, guint *off
proto_tree_add_item(tree, hf_zbee_zcl_calendar_total_number_of_commands, tvb, *offset, 1, ENC_NA);
*offset += 1;
for (gint i = 0; tvb_reported_length_remaining(tvb, *offset) >= 5; i++) {
while (tvb_reported_length_remaining(tvb, *offset) >= 5) {
/* Season Start Date */
dissect_zcl_date(tvb, tree, offset, ett_zbee_zcl_calendar_season_start_date, "Season Start Date", hf_zbee_zcl_calendar_date_year, hf_zbee_zcl_calendar_date_month, hf_zbee_zcl_calendar_date_month_day, hf_zbee_zcl_calendar_date_week_day);

5
file.c
View File

@ -569,8 +569,6 @@ cf_read(capture_file *cf, gboolean reloading)
ws_buffer_init(&buf, 1514);
TRY {
guint32 count = 0;
gint64 file_pos;
gint64 data_offset;
@ -588,7 +586,6 @@ cf_read(capture_file *cf, gboolean reloading)
too_many_records = TRUE;
break;
}
count++;
file_pos = wtap_read_so_far(cf->provider.wth);
/* Create the progress bar if necessary. */
@ -4533,7 +4530,6 @@ rescan_file(capture_file *cf, const char *fname, gboolean is_tempfile)
gchar status_str[100];
guint32 framenum;
frame_data *fdata;
int count = 0;
/* Close the old handle. */
wtap_close(cf->provider.wth);
@ -4597,7 +4593,6 @@ rescan_file(capture_file *cf, const char *fname, gboolean is_tempfile)
fdata->file_off = data_offset;
}
if (size >= 0) {
count++;
cf->f_datalen = wtap_read_so_far(cf->provider.wth);
/* Create the progress bar if necessary. */

View File

@ -139,7 +139,6 @@ scan_local_interfaces_filtered(GList * allowed_types, void (*update_cb)(void))
if_info_t *if_info, temp;
gchar *descr;
if_capabilities_t *caps=NULL;
gint linktype_count;
gboolean monitor_mode;
GSList *curr_addr;
int ips = 0, i;
@ -300,7 +299,6 @@ scan_local_interfaces_filtered(GList * allowed_types, void (*update_cb)(void))
device.remote_opts.sampling_method = global_capture_opts.default_options.sampling_method;
device.remote_opts.sampling_param = global_capture_opts.default_options.sampling_param;
#endif
linktype_count = 0;
device.links = NULL;
if (caps != NULL) {
#if defined(HAVE_PCAP_CREATE)
@ -321,7 +319,6 @@ scan_local_interfaces_filtered(GList * allowed_types, void (*update_cb)(void))
link->name = ws_strdup_printf("%s (not supported)", data_link_info->name);
}
device.links = g_list_append(device.links, link);
linktype_count++;
}
/*

View File

@ -1929,7 +1929,7 @@ void IOGraph::clearAllData()
void IOGraph::recalcGraphData(capture_file *cap_file, bool enable_scaling)
{
/* Moving average variables */
unsigned int mavg_in_average_count = 0, mavg_left = 0, mavg_right = 0;
unsigned int mavg_in_average_count = 0, mavg_left = 0;
unsigned int mavg_to_remove = 0, mavg_to_add = 0;
double mavg_cumulated = 0;
QCPAxis *x_axis = nullptr;
@ -1964,7 +1964,6 @@ void IOGraph::recalcGraphData(capture_file *cap_file, bool enable_scaling)
mavg_cumulated += getItemValue((int)warmup_interval / interval_, cap_file);
mavg_in_average_count++;
mavg_right++;
}
mavg_to_add = (unsigned int)warmup_interval;
}
@ -1989,8 +1988,6 @@ void IOGraph::recalcGraphData(capture_file *cap_file, bool enable_scaling)
mavg_in_average_count++;
mavg_cumulated += getItemValue((int)mavg_to_add / interval_, cap_file);
mavg_to_add += interval_;
} else {
mavg_right--;
}
}
if (mavg_in_average_count > 0) {

View File

@ -1139,7 +1139,6 @@ int ProfileModel::importProfilesFromDir(QString dirname, int * skippedCnt, bool
{
QFileInfoList entries = uniquePaths(filterProfilePath(dirname, QFileInfoList(), fromZip));
int entryCount = 0;
foreach (QFileInfo fentry, entries)
{
if (fentry.fileName().length() <= 0)
@ -1148,8 +1147,6 @@ int ProfileModel::importProfilesFromDir(QString dirname, int * skippedCnt, bool
bool wasEmpty = true;
bool success = false;
entryCount++;
QString profilePath = profileDir.absolutePath() + "/" + fentry.fileName();
QString tempPath = fentry.absoluteFilePath();

View File

@ -163,7 +163,6 @@ void StatsTreeDialog::drawTreeItems(void *st_ptr)
if (!st || !st->cfg || !st->cfg->pr || !st->cfg->pr->st_dlg) return;
TapParameterDialog *st_dlg = st->cfg->pr->st_dlg;
QTreeWidgetItemIterator iter(st_dlg->statsTreeWidget());
int node_count = 0;
while (*iter) {
stat_node *node = VariantPointer<stat_node>::asPtr((*iter)->data(item_col_, Qt::UserRole));
@ -177,7 +176,6 @@ void StatsTreeDialog::drawTreeItems(void *st_ptr)
(!(node->st_flags&ST_FLG_DEF_NOEXPAND)));
g_free(valstrs);
}
node_count++;
++iter;
}

View File

@ -453,7 +453,6 @@ static void insert_to_graph_t38(voip_calls_tapinfo_t *tapinfo, packet_info *pinf
{
seq_analysis_item_t *gai, *new_gai;
GList *list;
guint item_num;
gboolean inserted;
gchar time_str[COL_MAX_LEN];
@ -484,7 +483,6 @@ static void insert_to_graph_t38(voip_calls_tapinfo_t *tapinfo, packet_info *pinf
new_gai->time_str = g_strdup(time_str);
new_gai->display=FALSE;
item_num = 0;
inserted = FALSE;
list = g_queue_peek_nth_link(tapinfo->graph_analysis->items, 0);
@ -498,7 +496,6 @@ static void insert_to_graph_t38(voip_calls_tapinfo_t *tapinfo, packet_info *pinf
break;
}
list = g_list_next(list);
item_num++;
}
if (!inserted) {