Grab-bag of dead initializers and two actual bugs.
authorEvan Huus <eapache@gmail.com>
Sun, 25 May 2014 15:13:04 +0000 (11:13 -0400)
committerEvan Huus <eapache@gmail.com>
Sun, 25 May 2014 18:12:00 +0000 (18:12 +0000)
All caught by cppcheck. The two (semi)-interesting bugs are:
- in asn1/atn-cpdlc/packet-atn-cpdlc-template.c where the break statement should
  have been inside the brace, causing potential control-flow weirdness with
  exceptions
- in epan/dissectors/packet-ieee80211.c where the bounds check for tag_len did
  not match the expert info given

Change-Id: Ie173fb8d917aabb9b4571435d671d6f16e1c7569
Reviewed-on: https://code.wireshark.org/review/1793
Reviewed-by: Alexis La Goutte <alexis.lagoutte@gmail.com>
Reviewed-by: Evan Huus <eapache@gmail.com>
14 files changed:
asn1/atn-cm/packet-atn-cm-template.c
asn1/atn-cpdlc/packet-atn-cpdlc-template.c
epan/dissectors/packet-asterix.c
epan/dissectors/packet-atn-cm.c
epan/dissectors/packet-atn-cpdlc.c
epan/dissectors/packet-batadv.c
epan/dissectors/packet-dcerpc-netlogon.c
epan/dissectors/packet-dcerpc-nt.c
epan/dissectors/packet-dcp-etsi.c
epan/dissectors/packet-ieee80211.c
epan/dissectors/packet-lisp.c
epan/dissectors/packet-mac-lte.c
epan/dissectors/packet-mongo.c
epan/dissectors/packet-openflow_v5.c

index c2bc0da5b6e3cb7e9c67493f5a3d77d605b26f8b..a666293c2f75cebfa4ba6d49347639fb5422f86a 100644 (file)
@@ -74,9 +74,9 @@ dissect_atn_cm(
                proto_tree *tree,
                void *data _U_)
 {
-               int     type = no_msg;
-               proto_item *ti = NULL;
-               proto_tree *sub_tree = NULL;
+               int     type;
+               proto_item *ti;
+               proto_tree *sub_tree;
 
                ti = proto_tree_add_text(
                        tree,
index 66f0a83c3bed5bc28ad5de637a08e9818aa1d838..b0ba23c4d9e219005d1f3edd20dc254044a9740d 100644 (file)
@@ -218,7 +218,7 @@ dissect_atn_cpdlc_heur(
                atn_conversation_t *atn_cv = NULL;
                volatile gboolean is_atn_cpdlc = FALSE;
                volatile gboolean is_pm = FALSE;
-               int type = no_msg;
+               int type;
 
                type = check_heur_msg_type(pinfo);
 
@@ -227,8 +227,8 @@ dissect_atn_cpdlc_heur(
                                        TRY {
                                                dissect_ProtectedGroundPDUs_PDU(tvb, pinfo, NULL);
                                                is_atn_cpdlc = TRUE;
-                                               is_pm = TRUE;}
-                                               break;
+                                               is_pm = TRUE;
+                                               break;}
                                        CATCH_ALL{
                                                is_atn_cpdlc = FALSE;
                                                is_pm = FALSE;}
index 759e0f0b76c24dc0fe790907af5aa047d0efcbad..a2b3649851489a159528c74569b0d3f6a8f3313b 100644 (file)
@@ -7005,15 +7005,13 @@ static void dissect_asterix_packet (tvbuff_t *tvb, proto_tree *tree)
     guint i;
     guint8 category;
     guint16 length;
-    proto_item *asterix_packet_item = NULL;
-    proto_tree *asterix_packet_tree = NULL;
+    proto_item *asterix_packet_item;
+    proto_tree *asterix_packet_tree;
 
     for (i = 0; i < tvb_reported_length (tvb); i += length + 3) {
         category = tvb_get_guint8 (tvb, i);
         length = (tvb_get_guint8 (tvb, i + 1) << 8) + tvb_get_guint8 (tvb, i + 2) - 3; /* -3 for category and length */
 
-        asterix_packet_item = NULL;
-        asterix_packet_tree = NULL;
         asterix_packet_item = proto_tree_add_item (tree, proto_asterix, tvb, i, length + 3, ENC_NA);
         proto_item_append_text (asterix_packet_item, ", Category %03d", category);
         asterix_packet_tree = proto_item_add_subtree (asterix_packet_item, ett_asterix);
@@ -7117,7 +7115,6 @@ static void asterix_build_subtree (tvbuff_t *tvb, guint offset, proto_tree *pare
 
     if (field->part != NULL) {
         for (i = 0, inner_offset = 0, go_on = 1; go_on && field->part[i] != NULL; i++) {
-            value = G_GINT64_CONSTANT(0);;
             value = tvb_get_bits64 (tvb, offset * 8 + inner_offset, field->part[i]->bit_length, ENC_BIG_ENDIAN);
             if (field->part[i]->hf != NULL) {
                 switch (field->part[i]->type) {
index e7ca5a1278567d4388f28dbefff4b2e9801dc7cf..d7fd33dd6c0f6ea255d9a1ea837d9dbaba8ece38 100644 (file)
@@ -641,9 +641,9 @@ dissect_atn_cm(
                proto_tree *tree,
                void *data _U_)
 {
-               int     type = no_msg;
-               proto_item *ti = NULL;
-               proto_tree *sub_tree = NULL;
+               int     type;
+               proto_item *ti;
+               proto_tree *sub_tree;
 
                ti = proto_tree_add_text(
                        tree,
index 5ff3d39e7f05841856f71cb5bd0bf3dc4b531fbf..e21ffa70c0fa57da673f7b9e29a92bc7a5ed4911 100644 (file)
@@ -5415,7 +5415,7 @@ dissect_atn_cpdlc_heur(
                atn_conversation_t *atn_cv = NULL;
                volatile gboolean is_atn_cpdlc = FALSE;
                volatile gboolean is_pm = FALSE;
-               int type = no_msg;
+               int type;
 
                type = check_heur_msg_type(pinfo);
 
@@ -5424,8 +5424,8 @@ dissect_atn_cpdlc_heur(
                                        TRY {
                                                dissect_ProtectedGroundPDUs_PDU(tvb, pinfo, NULL);
                                                is_atn_cpdlc = TRUE;
-                                               is_pm = TRUE;}
-                                               break;
+                                               is_pm = TRUE;
+                                               break;}
                                        CATCH_ALL{
                                                is_atn_cpdlc = FALSE;
                                                is_pm = FALSE;}
index 3dae4aef9c247f7c00d56f13be55af889538232a..1a52fc45d5d6bd9a9d452771bf23c19d2bd82fd5 100644 (file)
@@ -2238,7 +2238,7 @@ static void dissect_batadv_unicast_frag_v12(tvbuff_t *tvb, packet_info *pinfo, p
        proto_item *tf;
        struct unicast_frag_packet_v12 *unicast_frag_packeth;
        const guint8  *dest_addr, *orig_addr;
-       gboolean save_fragmented = FALSE;
+       gboolean save_fragmented;
        fragment_head *frag_msg = NULL;
        proto_tree *batadv_unicast_frag_tree = NULL, *flag_tree;
 
@@ -2344,7 +2344,7 @@ static void dissect_batadv_unicast_frag_v14(tvbuff_t *tvb, packet_info *pinfo, p
        proto_item *tf;
        struct unicast_frag_packet_v14 *unicast_frag_packeth;
        const guint8  *dest_addr, *orig_addr;
-       gboolean save_fragmented = FALSE;
+       gboolean save_fragmented;
        fragment_head *frag_msg = NULL;
        proto_tree *batadv_unicast_frag_tree = NULL, *flag_tree;
 
index 52527bd2b37586b17c4ee1d824f75f2006c215b5..c2ad75935ecd752bfffb1403db09cf23b9bd21fd 100644 (file)
@@ -2502,7 +2502,6 @@ netlogon_dissect_netrserverreqchallenge_rqst(tvbuff_t *tvb, int offset,
     vars->next = NULL;
 
     generate_hash_key(pinfo,0,key,NULL);
-    existing_vars = NULL;
     existing_vars = (netlogon_auth_vars *)g_hash_table_lookup(netlogon_auths, key);
     if (!existing_vars) {
         debugprintf("Adding initial vars with this start packet = %d\n",vars->start);
index 9101974cc074c88c2b81e5e52c67c66a06d58f69..d24c3ab6fce8df8508ab4a080fc034ed657bd559 100644 (file)
@@ -82,7 +82,7 @@ dissect_ndr_datablob(tvbuff_t *tvb, int offset, packet_info *pinfo,
 {
        proto_item *item;
        guint3264 len;
-       proto_tree *subtree = tree;
+       proto_tree *subtree;
 
        item = proto_tree_add_text(tree, tvb, offset, 0, "%s",
                        proto_registrar_get_name(hf_index));
index 30265927677a14b59af8943b9d2f3cf59dbc0dbf..26ecf654f9e44a27ab3760f76199b225f6ac2b3e 100644 (file)
@@ -339,7 +339,7 @@ dissect_pft_fec_detailed(tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree,
     }
   }
   if(new_tvb && tvb_length(new_tvb) > 0) {
-    gboolean decoded = TRUE;
+    gboolean decoded;
     tvbuff_t *dtvb = NULL;
     const guint8 *input = tvb_get_ptr(new_tvb, 0, -1);
     guint32 reassembled_size = tvb_length(new_tvb);
index d35d63d7fc3aaac6fd707b7fdd4784d868264478..6ea6aabe2296d673fbb14b7dd6c7349d086b08de 100644 (file)
@@ -10757,7 +10757,7 @@ dissect_vht_tx_pwr_envelope(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
   guint8 opt_ie_cnt=0;
   guint8 i;
 
-  if (tag_len < 2 && tag_len <= 5) {
+  if (tag_len < 2 || tag_len > 5) {
     expert_add_info_format(pinfo, ti_len, &ei_ieee80211_tag_length,
                            "VHT TX PWR Envelope IE length %u wrong, must be >= 2 and <= 5", tag_len);
     return offset;
@@ -11434,7 +11434,7 @@ dissect_wapi_param_set(tvbuff_t *tvb, packet_info *pinfo,
   /* Parse the WAPI Parameter Set IE Here*/
   proto_item *item;
   proto_tree *subtree;
-  guint16 loop_cnt, version  = 1, akm_cnt  = 1, ucast_cnt = 1, bkid_cnt = 1;
+  guint16 loop_cnt, version, akm_cnt  = 1, ucast_cnt = 1, bkid_cnt = 1;
   guint8  akm_suite_type = 0, ucast_cipher_type = 0, mcast_cipher_type = 0;
 
   version = tvb_get_letohs(tvb, offset);
index 2b77a43046503338348ce5308181502c59428c73..3c87d277d81a05f14f6de4d102be47e0b7c61647 100644 (file)
@@ -2101,11 +2101,11 @@ dissect_lisp_map_request(tvbuff_t *tvb, packet_info *pinfo, proto_tree *lisp_tre
     guint16            addr_len    = 0;
     gint               offset      = 0;
     guint16            flags;
-    gboolean           mrep        = FALSE;
-    gboolean           smr         = FALSE;
-    gboolean           probe       = FALSE;
-    gboolean           pitr        = FALSE;
-    gboolean           smr_invoked = FALSE;
+    gboolean           mrep;
+    gboolean           smr;
+    gboolean           probe;
+    gboolean           pitr;
+    gboolean           smr_invoked;
     guint8             itr_rec_cnt = 0;
     guint8             rec_cnt     = 0;
     guint16            src_eid_afi;
@@ -2350,7 +2350,7 @@ dissect_lisp_map_reply(tvbuff_t *tvb, packet_info *pinfo, proto_tree *lisp_tree)
 {
     int       i;
     gint      offset  = 0;
-    gboolean  probe   = FALSE;
+    gboolean  probe;
     guint8    flags;
     guint8    rec_cnt = 0;
     tvbuff_t *next_tvb;
@@ -2437,8 +2437,8 @@ dissect_lisp_map_register(tvbuff_t *tvb, packet_info *pinfo, proto_tree *lisp_tr
     tvbuff_t *next_tvb;
     guint16   authlen = 0;
     guint16   flags;
-    gboolean  xtrid   = FALSE;
-    gboolean  rtr     = FALSE;
+    gboolean  xtrid;
+    gboolean  rtr;
 
     /* Flags (1 bit) */
     proto_tree_add_item(lisp_tree, hf_lisp_mreg_flags_pmr, tvb, offset, 3, ENC_BIG_ENDIAN);
@@ -2550,8 +2550,8 @@ dissect_lisp_map_notify(tvbuff_t *tvb, packet_info *pinfo, proto_tree *lisp_tree
     tvbuff_t *next_tvb;
     guint16   authlen = 0;
     guint16   flags;
-    gboolean  xtrid   = FALSE;
-    gboolean  rtr     = FALSE;
+    gboolean  xtrid;
+    gboolean  rtr;
 
     /* Flags defined in NAT Traversal draft (2 bits) */
     flags = tvb_get_ntohs(tvb, offset);
index 7b6775a16587bbbbca4e144c0aa1d0001dcd9d0b..02f5f51f172e37e68083dd473f33bb7d4ad78ab3 100644 (file)
@@ -1389,9 +1389,7 @@ static guint mac_lte_framenum_instance_hash_func(gconstpointer v)
 {
     const drx_state_key_t *p1 = (const drx_state_key_t*)v;
 
-    /* XXX which one return ? */
     return p1->frameNumber + (p1->pdu_instance >> 8);
-    return GPOINTER_TO_UINT(v);
 }
 
 
@@ -4275,6 +4273,10 @@ static void dissect_ulsch_or_dlsch(tvbuff_t *tvb, packet_info *pinfo, proto_tree
                                 curr_offset++;
                             }
                         } else {
+                            /* XXX dead code? Expression is always false because
+                             * the condition matches previous condition in the
+                             * original if (so if it were true we'd never get
+                             * to this 'else' block in the first place) */
                             if ((gint16)(computed_header_offset + 1 - curr_offset) != pdu_lengths[n]) {
                                 expert_add_info_format(pinfo, ephr_ti, &ei_mac_lte_control_element_size_invalid,
                                     "Control Element has an unexpected size (computed=%d, actual=%d)",
index 574c1707adc2134fe3c41b4e234347a86c85a253..f0b80e6a3861c286209eedda92d1ad43964743e3 100644 (file)
@@ -291,7 +291,7 @@ dissect_bson_document(tvbuff_t *tvb, packet_info *pinfo, guint offset, proto_tre
 
   do {
     /* Read document elements */
-    guint8 e_type = -1;  /* Element type */
+    guint8 e_type;  /* Element type */
     gint str_len = -1;   /* String length */
     gint e_len = -1;     /* Element length */
     gint doc_len = -1;   /* Document length */
index 3e81d8e90a4bfe1d6835e5eedc5362d2e54975e2..410d95c82d97d5ab55989e63b4025b4408dcf496 100644 (file)
@@ -2513,7 +2513,6 @@ dissect_openflow_port_desc_prop_ethernet_v5(tvbuff_t *tvb, packet_info *pinfo _U
     offset+=4;
 
     return offset;
-    return offset;
 }