As suggested by Chris: use val_to_str_const() instead of match_strval() plus a
authormorriss <morriss@f5534014-38df-0310-8fa8-9805f1628bb7>
Tue, 17 May 2011 18:58:40 +0000 (18:58 +0000)
committermorriss <morriss@f5534014-38df-0310-8fa8-9805f1628bb7>
Tue, 17 May 2011 18:58:40 +0000 (18:58 +0000)
NULL-return check.

Use val_to_str_const instead of val_to_str() in a couple places where the string
is constant.

Use val_to_str() instead of blindly passing the return value from match_strval()
into a format routine (to ensure a non-NULL string pointer).  A couple of these
were cases where it could not actually return NULL, but I changed it for
consistency.

Store the return value of match_strval() rather than calling it repeatedly.

git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@37204 f5534014-38df-0310-8fa8-9805f1628bb7

epan/dissectors/packet-amqp.c
epan/dissectors/packet-ansi_637.c
epan/dissectors/packet-gsm_a_gm.c
epan/dissectors/packet-hci_h1.c
epan/dissectors/packet-ieee80211.c
epan/dissectors/packet-ncp-nmas.c
epan/dissectors/packet-ncp-sss.c
epan/dissectors/packet-rpc.c
epan/dissectors/packet-ses.c
epan/dissectors/packet-spp.c

index 6a6c0519f26a51bce02ad2a759ed140af22991ed..cbe0174598881022ffaad8e9ad4f8372bfc5fd15 100644 (file)
@@ -2353,9 +2353,8 @@ dissect_amqp_0_10_connection(tvbuff_t *tvb,
     const gchar* method_name;
 
     method = tvb_get_guint8(tvb, offset+1);
-    method_name = match_strval(method, amqp_0_10_connection_methods);
-    if (method_name == NULL)
-        method_name = "<invalid connection method>";
+    method_name = val_to_str_const(method, amqp_0_10_connection_methods,
+                                   "<invalid connection method>");
     if (check_col(pinfo->cinfo, COL_INFO)) {
         col_append_str(pinfo->cinfo, COL_INFO, method_name);
         col_append_str(pinfo->cinfo, COL_INFO, " ");
@@ -2695,9 +2694,8 @@ dissect_amqp_0_10_session(tvbuff_t *tvb,
     const gchar* method_name;
 
     method = tvb_get_guint8(tvb, offset+1);
-    method_name = match_strval(method, amqp_0_10_session_methods);
-    if (method_name == NULL)
-        method_name = "<invalid session method>";
+    method_name = val_to_str_const(method, amqp_0_10_session_methods,
+                                   "<invalid session method>");
     if (check_col(pinfo->cinfo, COL_INFO)) {
         col_append_str(pinfo->cinfo, COL_INFO, method_name);
         col_append_str(pinfo->cinfo, COL_INFO, " ");
@@ -2969,9 +2967,8 @@ dissect_amqp_0_10_execution(tvbuff_t *tvb,
     const gchar* method_name;
 
     method = tvb_get_guint8(tvb, offset+1);
-    method_name = match_strval(method, amqp_0_10_execution_methods);
-    if (method_name == NULL)
-        method_name = "<invalid execution method>";
+    method_name = val_to_str_const(method, amqp_0_10_execution_methods,
+                                   "<invalid execution method>");
     if (check_col(pinfo->cinfo, COL_INFO)) {
         col_append_str(pinfo->cinfo, COL_INFO, method_name);
         col_append_str(pinfo->cinfo, COL_INFO, " ");
@@ -3160,9 +3157,8 @@ dissect_amqp_0_10_message(tvbuff_t *tvb,
     const gchar* method_name;
 
     method = tvb_get_guint8(tvb, offset+1);
-    method_name = match_strval(method, amqp_0_10_message_methods);
-    if (method_name == NULL)
-        method_name = "<invalid message method>";
+    method_name = val_to_str_const(method, amqp_0_10_message_methods,
+                                   "<invalid message method>");
     if (check_col(pinfo->cinfo, COL_INFO)) {
         col_append_str(pinfo->cinfo, COL_INFO, method_name);
         col_append_str(pinfo->cinfo, COL_INFO, " ");
@@ -3512,9 +3508,8 @@ dissect_amqp_0_10_tx(tvbuff_t *tvb,
     const gchar* method_name;
 
     method = tvb_get_guint8(tvb, offset+1);
-    method_name = match_strval(method, amqp_0_10_tx_methods);
-    if (method_name == NULL)
-        method_name = "<invalid tx method>";
+    method_name = val_to_str_const(method, amqp_0_10_tx_methods,
+                                   "<invalid tx method>");
     if (check_col(pinfo->cinfo, COL_INFO)) {
         col_append_str(pinfo->cinfo, COL_INFO, method_name);
         col_append_str(pinfo->cinfo, COL_INFO, " ");
@@ -3556,9 +3551,8 @@ dissect_amqp_0_10_dtx(tvbuff_t *tvb,
     const gchar* method_name;
 
     method = tvb_get_guint8(tvb, offset+1);
-    method_name = match_strval(method, amqp_0_10_dtx_methods);
-    if (method_name == NULL)
-        method_name = "<invalid dtx method>";
+    method_name = val_to_str_const(method, amqp_0_10_dtx_methods,
+                                   "<invalid dtx method>");
     if (check_col(pinfo->cinfo, COL_INFO)) {
         col_append_str(pinfo->cinfo, COL_INFO, method_name);
         col_append_str(pinfo->cinfo, COL_INFO, " ");
@@ -3757,9 +3751,8 @@ dissect_amqp_0_10_exchange(tvbuff_t *tvb,
     const gchar* method_name;
 
     method = tvb_get_guint8(tvb, offset+1);
-    method_name = match_strval(method, amqp_0_10_exchange_methods);
-    if (method_name == NULL)
-        method_name = "<invalid exchange method>";
+    method_name = val_to_str_const(method, amqp_0_10_exchange_methods,
+                                   "<invalid exchange method>");
     if (check_col(pinfo->cinfo, COL_INFO)) {
         col_append_str(pinfo->cinfo, COL_INFO, method_name);
         col_append_str(pinfo->cinfo, COL_INFO, " ");
@@ -4026,9 +4019,8 @@ dissect_amqp_0_10_queue(tvbuff_t *tvb,
     const gchar* method_name;
 
     method = tvb_get_guint8(tvb, offset+1);
-    method_name = match_strval(method, amqp_0_10_queue_methods);
-    if (method_name == NULL)
-        method_name = "<invalid queue method>";
+    method_name = val_to_str_const(method, amqp_0_10_queue_methods,
+                                   "<invalid queue method>");
     if (check_col(pinfo->cinfo, COL_INFO)) {
         col_append_str(pinfo->cinfo, COL_INFO, method_name);
         col_append_str(pinfo->cinfo, COL_INFO, " ");
@@ -4187,9 +4179,8 @@ dissect_amqp_0_10_file(tvbuff_t *tvb,
     const gchar* method_name;
 
     method = tvb_get_guint8(tvb, offset+1);
-    method_name = match_strval(method, amqp_0_10_file_methods);
-    if (method_name == NULL)
-        method_name = "<invalid file method>";
+    method_name = val_to_str_const(method, amqp_0_10_file_methods,
+                                   "<invalid file method>");
     if (check_col(pinfo->cinfo, COL_INFO)) {
         col_append_str(pinfo->cinfo, COL_INFO, method_name);
         col_append_str(pinfo->cinfo, COL_INFO, " ");
@@ -4528,9 +4519,8 @@ dissect_amqp_0_10_stream(tvbuff_t *tvb,
     const gchar* method_name;
 
     method = tvb_get_guint8(tvb, offset+1);
-    method_name = match_strval(method, amqp_0_10_stream_methods);
-    if (method_name == NULL)
-        method_name = "<invalid stream method>";
+    method_name = val_to_str_const(method, amqp_0_10_stream_methods,
+                                   "<invalid stream method>");
     if (check_col(pinfo->cinfo, COL_INFO)) {
         col_append_str(pinfo->cinfo, COL_INFO, method_name);
         col_append_str(pinfo->cinfo, COL_INFO, " ");
index 39d6be0873236cf5b00574e06272f7325962ea8a..3c20368227adcf5e0816fcf75b59380e985d53aa 100644 (file)
@@ -1339,9 +1339,7 @@ trans_param_srvc_cat(tvbuff_t *tvb, proto_tree *tree, guint len, guint32 offset,
 
     value = tvb_get_ntohs(tvb, offset);
 
-    str = match_strval(value, ansi_srvc_cat_strings);
-
-    if (NULL == str) str = "Reserved";
+    str = val_to_str_const(value, ansi_srvc_cat_strings, "Reserved");
 
     proto_tree_add_text(tree, tvb, offset, 2,
        "%s", str);
index 1427b3612b4f6c041352e2e74add2fe159799c22..cf8e2468bdb11edf95173bf7479da0cc68cc1d1b 100644 (file)
@@ -1231,7 +1231,7 @@ de_gmm_ms_radio_acc_cap(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo, gui
                GET_DATA;
 
                bits_length = curr_bits_length = oct>>(32-bits_needed);
-               
+
                proto_tree_add_bits_item(tf_tree, hf_gsm_a_gm_acc_cap_struct_len, tvb, bit_offset, 7, FALSE);
                proto_item_set_len(tf, (bits_length>>3)+1);
                /* This is already done - length doesn't contain this field
@@ -2770,7 +2770,7 @@ de_gmm_req_ms_info(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_, guin
 {
        guint32 curr_offset;
        guint32 bit_offset;
-       
+
        curr_offset = offset;
        bit_offset = (curr_offset<<3)+4;
 
@@ -2781,13 +2781,13 @@ de_gmm_req_ms_info(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_, guin
        proto_tree_add_bits_item(tree, hf_gsm_a_spare_bits, tvb, bit_offset, 2, ENC_BIG_ENDIAN);
        bit_offset+=2;
        curr_offset++;
-       
+
        return len;
 }
 
 /* [7] 10.5.5.26 UE network capability
  * See subclause 9.9.3.x in 3GPP TS 24.301 [120].
- */ 
+ */
 
 /* [7] 10.5.5.27 E-UTRAN inter RAT information container */
 static guint16
@@ -2827,7 +2827,7 @@ de_gmm_voice_domain_pref(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_
 {
        guint32 curr_offset;
        guint32 bit_offset;
-       
+
        curr_offset = offset;
        bit_offset = curr_offset<<3;
 
@@ -3098,7 +3098,7 @@ static const true_false_string gsm_a_gm_nsapi_ul_stat_vals = {
        "uplink data are pending for the preserved PDP context",
        "no uplink data are pending for the preserved PDP context or the PDP context is PDP-INACTIVE or is PDP-ACTIVE with a RAB already established"
 };
+
 static guint16
 de_gc_uplink_data_stat(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_, guint32 offset, guint len, gchar *add_string _U_, int string_len _U_)
 {
@@ -3134,7 +3134,7 @@ de_gc_uplink_data_stat(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_,
        proto_tree_add_bits_item(tree, hf_gsm_a_gm_nsapi_8_ul_stat, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
        bit_offset++;
        curr_offset++;
-       
+
        return(len);
 }
 
@@ -3958,11 +3958,10 @@ de_sm_cause(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_, guint32 off
        const gchar     *str;
 
        oct = tvb_get_guint8(tvb, offset);
-       str = match_strval(oct, gsm_a_sm_cause_vals);
 
        /* SM Cause can be sent in both directions */
-       if (!str)
-               str = "Protocol error, unspecified / Service option temporarily out of order";
+       str = val_to_str_const(oct, gsm_a_sm_cause_vals,
+                              "Protocol error, unspecified / Service option temporarily out of order");
 
        proto_tree_add_uint_format_value(tree, hf_gsm_a_sm_cause, tvb,
                                offset, 1, oct, "%s (%u)", str, oct);
@@ -3981,11 +3980,10 @@ de_sm_cause_2(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_, guint32 o
        const gchar     *str;
 
        oct = tvb_get_guint8(tvb, offset);
-       str = match_strval(oct, gsm_a_sm_cause_vals);
 
        /* SM Cause 2 is sent only in the Network-to-MS direction */
-       if (!str)
-               str = "Service option temporarily out of order";
+       str = val_to_str_const(oct, gsm_a_sm_cause_vals,
+                              "Service option temporarily out of order");
 
        proto_tree_add_uint_format_value(tree, hf_gsm_a_sm_cause_2, tvb,
                                offset, 1, oct, "%s (%u)", str, oct);
@@ -4686,7 +4684,7 @@ dtap_gmm_attach_req(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo, guint32
        ELEM_OPT_TV_SHORT( 0x90 , GSM_A_PDU_TYPE_GM, DE_TMSI_STAT , NULL);
 
        ELEM_OPT_TLV( 0x33 , GSM_A_PDU_TYPE_GM, DE_PS_LCS_CAP , NULL);
-       
+
        ELEM_OPT_TLV(0x11, GSM_A_PDU_TYPE_COMMON, DE_MS_CM_2, NULL);
 
        ELEM_OPT_TLV(0x20, GSM_A_PDU_TYPE_COMMON, DE_MS_CM_3, NULL);
@@ -4754,11 +4752,11 @@ dtap_gmm_attach_acc(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo, guint32
        ELEM_OPT_TV_SHORT( 0xB0 , GSM_A_PDU_TYPE_GM, DE_NET_FEAT_SUP , NULL);
 
        ELEM_OPT_TLV( 0x34 , GSM_A_PDU_TYPE_DTAP, DE_EMERGENCY_NUM_LIST , NULL);
-       
+
        ELEM_OPT_TV_SHORT( 0xA0 , GSM_A_PDU_TYPE_GM , DE_REQ_MS_INFO , NULL);
-       
+
        ELEM_OPT_TLV( 0x37 , GSM_A_PDU_TYPE_GM, DE_GPRS_TIMER_2 , " - T3319" );
-       
+
        ELEM_OPT_TLV( 0x38 , GSM_A_PDU_TYPE_GM, DE_GPRS_TIMER_2 , " - T3323" );
 
        EXTRANEOUS_DATA_CHECK_EXPERT(curr_len, 0, pinfo);
index a8e2d030620e57e5d9a32ed46f420458a09a76f5..5d7b7ebf5096466cfefc9c176e2aca094f1820b5 100644 (file)
@@ -71,12 +71,12 @@ dissect_hci_h1(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
        if(tree){
                ti = proto_tree_add_item(tree, proto_hci_h1, tvb, 0, 0, FALSE);
                hci_h1_tree = proto_item_add_subtree(ti, ett_hci_h1);
-               
+
                if(pinfo->p2p_dir == P2P_DIR_SENT ||
                   pinfo->p2p_dir == P2P_DIR_RECV)
                        proto_item_append_text(hci_h1_tree, " %s %s",
-                                              match_strval(pinfo->p2p_dir,
-                                                           hci_h1_direction_vals),
+                                              val_to_str(pinfo->p2p_dir,
+                                                         hci_h1_direction_vals, "Unknown: %d"),
                                               val_to_str(type,
                                                          hci_h1_type_vals,
                                                          "Unknown 0x%02x"));
@@ -91,8 +91,8 @@ dissect_hci_h1(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
                if(pinfo->p2p_dir == P2P_DIR_SENT ||
                   pinfo->p2p_dir == P2P_DIR_RECV)
                        col_add_fstr(pinfo->cinfo, COL_INFO, "%s %s",
-                                    match_strval(pinfo->p2p_dir,
-                                                 hci_h1_direction_vals),
+                                    val_to_str(pinfo->p2p_dir,
+                                               hci_h1_direction_vals, "Unknown: %d"),
                                     val_to_str(type, hci_h1_type_vals,
                                                "Unknown 0x%02x"));
                else
index 43225c8a925c58cc84f1cff1d7bb834cdf2a75dc..e1fd3dff82da3f73a9d7da513cfab2a374ef30f4 100644 (file)
@@ -4699,7 +4699,7 @@ dissect_vendor_ie_wpawme(proto_item * item, proto_tree * tree, tvbuff_t * tag_tv
       byte2 = tvb_get_guint8(tag_tvb, tag_off + 1);
       g_snprintf(out_buff, SHORT_STR,
         "WME AC Parameters: ACI %u (%s), Admission Control %sMandatory, AIFSN %u, ECWmin %u, ECWmax %u, TXOP %u",
-         (byte1 & 0x60) >> 5, match_strval((byte1 & 0x60) >> 5, wme_acs),
+         (byte1 & 0x60) >> 5, val_to_str((byte1 & 0x60) >> 5, wme_acs, "(Unknown: %d)"),
          (byte1 & 0x10) ? "" : "not ", byte1 & 0x0f,
          byte2 & 0x0f, (byte2 & 0xf0) >> 4,
          tvb_get_letohs(tag_tvb, tag_off + 2));
@@ -5058,7 +5058,7 @@ dissect_vendor_ie_aironet(proto_item * aironet_item, proto_tree * ietree,
       txop = tvb_get_letohs(tvb, offset + 2);
       proto_tree_add_bytes_format(ietree, hf_ieee80211_aironet_ie_qos_val, tvb, offset, 4, NULL,
           "CCX QoS Parameters??: ACI %u (%s), Admission Control %sMandatory, AIFSN %u, ECWmin %u, ECWmax %u, TXOP %u",
-        (byte1 & 0x60) >> 5, match_strval((byte1 & 0x60) >> 5, wme_acs),
+        (byte1 & 0x60) >> 5, val_to_str((byte1 & 0x60) >> 5, wme_acs, "(Unknown: %d)"),
         (byte1 & 0x10) ? "" : "not ", byte1 & 0x0f,
         byte2 & 0x0f, (byte2 & 0xf0) >> 4,
         txop);
index ba70a11fdab146beac8dba73e3a3ca3e4805f125..fe40e14485e2c35fb4b9bdd0ba6b09e3ddfe5d88 100644 (file)
@@ -206,7 +206,7 @@ nmas_string(tvbuff_t* tvb, int hfinfo, proto_tree *nmas_tree, int offset, gboole
         guint16 c_char;
         guint32 length_remaining = 0;
 
-       buffer=ep_alloc(ITEM_LABEL_LENGTH+1);
+        buffer=ep_alloc(ITEM_LABEL_LENGTH+1);
         if (little) {
             str_length = tvb_get_letohl(tvb, foffset);
         }
@@ -224,18 +224,18 @@ nmas_string(tvbuff_t* tvb, int hfinfo, proto_tree *nmas_tree, int offset, gboole
         }
         if(str_length == 0)
         {
-                   proto_tree_add_string(nmas_tree, hfinfo, tvb, offset,
+            proto_tree_add_string(nmas_tree, hfinfo, tvb, offset,
                 4, "<Not Specified>");
             return foffset;
         }
-       /*
-        * XXX - other than the special-casing of null bytes,
-        * we could just use "proto_tree_add_item()", as for
-        * FT_STRING, FT_STRINGZ, and FT_UINT_STRING fields,
-        * the display representation of an item is generated
-        * using "format_text()", so it handles non-printable
-        * characters.
-        */
+        /*
+         * XXX - other than the special-casing of null bytes,
+         * we could just use "proto_tree_add_item()", as for
+         * FT_STRING, FT_STRINGZ, and FT_UINT_STRING fields,
+         * the display representation of an item is generated
+         * using "format_text()", so it handles non-printable
+         * characters.
+         */
         for ( i = 0; i < str_length; i++ )
         {
                 c_char = tvb_get_guint8(tvb, foffset );
@@ -261,8 +261,8 @@ nmas_string(tvbuff_t* tvb, int hfinfo, proto_tree *nmas_tree, int offset, gboole
 
                 if(length_remaining==1)
                 {
-                       i++;
-                       break;
+                        i++;
+                        break;
                 }
         }
         buffer[i] = '\0';
@@ -474,7 +474,7 @@ dissect_nmas_request(tvbuff_t *tvb, packet_info *pinfo, proto_tree *ncp_tree, nc
 }
 
 void
-dissect_nmas_reply(tvbuff_t *tvb, packet_info *pinfo, proto_tree *ncp_tree, guint8 func _U_, guint8 subfunc, ncp_req_hash_value        *request_value)
+dissect_nmas_reply(tvbuff_t *tvb, packet_info *pinfo, proto_tree *ncp_tree, guint8 func _U_, guint8 subfunc, ncp_req_hash_value *request_value)
 {
     guint32             foffset=0, roffset=0;
     guint32             subverb=0;
@@ -484,6 +484,7 @@ dissect_nmas_reply(tvbuff_t *tvb, packet_info *pinfo, proto_tree *ncp_tree, guin
     proto_tree          *atree;
     proto_item          *aitem;
     proto_item          *expert_item;
+    const gchar         *str;
 
 
     foffset = 8;
@@ -595,13 +596,12 @@ dissect_nmas_reply(tvbuff_t *tvb, packet_info *pinfo, proto_tree *ncp_tree, guin
                     break;
                 case 7:
                     encrypt_error = tvb_get_ntohl(tvb, foffset);
-                    if (match_strval(encrypt_error, nmas_errors_enum)!=NULL)
+                    str = match_strval(encrypt_error, nmas_errors_enum);
+                    if (str)
                     {
-                        if (check_col(pinfo->cinfo, COL_INFO)) {
-                           col_add_fstr(pinfo->cinfo, COL_INFO, "R Payload Error - %s", match_strval(encrypt_error, nmas_errors_enum));
-                        }
+                        col_add_fstr(pinfo->cinfo, COL_INFO, "R Payload Error - %s", str);
                         expert_item = proto_tree_add_item(atree, hf_encrypt_error, tvb, foffset, 4, FALSE);
-                        expert_add_info_format(pinfo, expert_item, PI_RESPONSE_CODE, PI_ERROR, "NMAS Payload Error: %s", match_strval(encrypt_error, nmas_errors_enum));
+                        expert_add_info_format(pinfo, expert_item, PI_RESPONSE_CODE, PI_ERROR, "NMAS Payload Error: %s", str);
                     }
                     else
                     {
@@ -620,13 +620,12 @@ dissect_nmas_reply(tvbuff_t *tvb, packet_info *pinfo, proto_tree *ncp_tree, guin
                 break;
             }
         }
-        if (match_strval(return_code, nmas_errors_enum)!=NULL)
+        str = match_strval(return_code, nmas_errors_enum);
+        if (str)
         {
             expert_item = proto_tree_add_item(atree, hf_return_code, tvb, roffset, 4, TRUE);
-            expert_add_info_format(pinfo, expert_item, PI_RESPONSE_CODE, PI_ERROR, "NMAS Error: 0x%08x %s", return_code, match_strval(return_code, nmas_errors_enum));
-            if (check_col(pinfo->cinfo, COL_INFO)) {
-               col_add_fstr(pinfo->cinfo, COL_INFO, "R Error - %s", match_strval(return_code, nmas_errors_enum));
-            }
+            expert_add_info_format(pinfo, expert_item, PI_RESPONSE_CODE, PI_ERROR, "NMAS Error: 0x%08x %s", return_code, str);
+            col_add_fstr(pinfo->cinfo, COL_INFO, "R Error - %s", str);
         }
         else
         {
@@ -656,27 +655,27 @@ proto_register_nmas(void)
 {
     static hf_register_info hf_nmas[] = {
         { &hf_func,
-        { "Function",          "nmas.func", FT_UINT8, BASE_HEX, NULL, 0x0,
+        { "Function", "nmas.func", FT_UINT8, BASE_HEX, NULL, 0x0,
             NULL, HFILL }},
 
         { &hf_subfunc,
-        { "Subfunction",               "nmas.subfunc", FT_UINT8, BASE_HEX, NULL, 0x0,
+        { "Subfunction", "nmas.subfunc", FT_UINT8, BASE_HEX, NULL, 0x0,
             NULL, HFILL }},
 
         { &hf_ping_version,
-        { "Ping Version",              "nmas.ping_version", FT_UINT32, BASE_HEX, NULL, 0x0,
+        { "Ping Version", "nmas.ping_version", FT_UINT32, BASE_HEX, NULL, 0x0,
             NULL, HFILL }},
 
         { &hf_ping_flags,
-        { "Flags",             "nmas.ping_flags", FT_UINT32, BASE_HEX, NULL, 0x0,
+        { "Flags", "nmas.ping_flags", FT_UINT32, BASE_HEX, NULL, 0x0,
             NULL, HFILL }},
 
         { &hf_frag_handle,
-        { "Fragment Handle",        "nmas.frag_handle", FT_UINT32, BASE_HEX, NULL, 0x0,
+        { "Fragment Handle", "nmas.frag_handle", FT_UINT32, BASE_HEX, NULL, 0x0,
             NULL, HFILL }},
 
         { &hf_length,
-        { "Length",        "nmas.length", FT_UINT32, BASE_DEC, NULL, 0x0,
+        { "Length", "nmas.length", FT_UINT32, BASE_DEC, NULL, 0x0,
             NULL, HFILL }},
 
         { &hf_subverb,
index 4840107954db6cd3ea13277283c6bfab495f635f..46a6a9c4f5e9e37ac8ba036039bff59e1abf982f 100644 (file)
@@ -171,8 +171,8 @@ process_flags(proto_tree *sss_tree, tvbuff_t *tvb, guint32 foffset)
 {
     gchar                   flags_str[1024];
     const gchar            *sep;
-    proto_item            *tinew;
-    proto_tree            *flags_tree;
+    proto_item             *tinew;
+    proto_tree             *flags_tree;
     guint32                 i;
     guint32                 bvalue = 0;
     guint32                 flags = 0;
@@ -293,7 +293,7 @@ process_flags(proto_tree *sss_tree, tvbuff_t *tvb, guint32 foffset)
     }
 
     tinew = proto_tree_add_uint_format(sss_tree, hf_flags, tvb, foffset, 4, flags, "%s 0x%08x", "Flags:", flags);
-       flags_tree = proto_item_add_subtree(tinew, ett_nds);
+    flags_tree = proto_item_add_subtree(tinew, ett_nds);
 
     bvalue = 0x00000001;
 
@@ -463,7 +463,7 @@ sss_string(tvbuff_t* tvb, int hfinfo, proto_tree *sss_tree, int offset, gboolean
         }
         if(str_length == 0)
         {
-                   proto_tree_add_string(sss_tree, hfinfo, tvb, offset,
+            proto_tree_add_string(sss_tree, hfinfo, tvb, offset,
                 4, "<Not Specified>");
             return foffset;
         }
@@ -492,8 +492,8 @@ sss_string(tvbuff_t* tvb, int hfinfo, proto_tree *sss_tree, int offset, gboolean
 
                 if(length_remaining==1)
                 {
-                       i++;
-                       break;
+                        i++;
+                        break;
                 }
         }
         buffer[i] = '\0';
@@ -666,7 +666,7 @@ dissect_sss_request(tvbuff_t *tvb, packet_info *pinfo, proto_tree *ncp_tree, ncp
 }
 
 void
-dissect_sss_reply(tvbuff_t *tvb, packet_info *pinfo, proto_tree *ncp_tree, guint8 subfunc, ncp_req_hash_value  *request_value)
+dissect_sss_reply(tvbuff_t *tvb, packet_info *pinfo, proto_tree *ncp_tree, guint8 subfunc, ncp_req_hash_value *request_value)
 {
     guint32             foffset=0;
     guint32             subverb=0;
@@ -675,6 +675,7 @@ dissect_sss_reply(tvbuff_t *tvb, packet_info *pinfo, proto_tree *ncp_tree, guint
     guint32             number_of_items=0;
     gint32              length_of_string=0;
     guint32             i = 0;
+    const gchar                *str;
 
     proto_tree          *atree;
     proto_item          *aitem;
@@ -698,8 +699,9 @@ dissect_sss_reply(tvbuff_t *tvb, packet_info *pinfo, proto_tree *ncp_tree, guint
     case 2:
         if (request_value) {
             subverb = request_value->req_nds_flags;
-            if (match_strval(subverb, sss_verb_enum)) {
-                proto_tree_add_text(atree, tvb, foffset, tvb_length_remaining(tvb, foffset), "Verb: %s", match_strval(subverb, sss_verb_enum));
+            str = match_strval(subverb, sss_verb_enum);
+            if (str) {
+                proto_tree_add_text(atree, tvb, foffset, tvb_length_remaining(tvb, foffset), "Verb: %s", str);
             }
         }
         proto_tree_add_item(atree, hf_length, tvb, foffset, 4, TRUE);
@@ -713,10 +715,11 @@ dissect_sss_reply(tvbuff_t *tvb, packet_info *pinfo, proto_tree *ncp_tree, guint
         {
             foffset += 4;
             return_code = tvb_get_letohl(tvb, foffset);
-            if ( match_strval(return_code, sss_errors_enum) != NULL )
+            str = match_strval(return_code, sss_errors_enum);
+            if (str)
             {
                 expert_item = proto_tree_add_item(atree, hf_return_code, tvb, foffset, 4, TRUE);
-                expert_add_info_format(pinfo, expert_item, PI_RESPONSE_CODE, PI_ERROR, "SSS Error: %s", match_strval(return_code, sss_errors_enum));
+                expert_add_info_format(pinfo, expert_item, PI_RESPONSE_CODE, PI_ERROR, "SSS Error: %s", str);
                 if (check_col(pinfo->cinfo, COL_INFO)) {
                    col_add_fstr(pinfo->cinfo, COL_INFO, "R Error - %s", val_to_str(return_code, sss_errors_enum, "Unknown (%d)"));
                 }
@@ -774,30 +777,30 @@ dissect_sss_reply(tvbuff_t *tvb, packet_info *pinfo, proto_tree *ncp_tree, guint
 void
 proto_register_sss(void)
 {
-       static hf_register_info hf_sss[] = {
-               { &hf_buffer_size,
-               { "Buffer Size",                "sss.buffer", FT_UINT32, BASE_DEC, NULL, 0x0,
-                       NULL, HFILL }},
+    static hf_register_info hf_sss[] = {
+        { &hf_buffer_size,
+        { "Buffer Size", "sss.buffer", FT_UINT32, BASE_DEC, NULL, 0x0,
+          NULL, HFILL }},
 
-               { &hf_ping_version,
-               { "Ping Version",               "sss.ping_version", FT_UINT32, BASE_HEX, NULL, 0x0,
-                       NULL, HFILL }},
+        { &hf_ping_version,
+        { "Ping Version", "sss.ping_version", FT_UINT32, BASE_HEX, NULL, 0x0,
+          NULL, HFILL }},
 
-               { &hf_flags,
-               { "Flags",              "sss.flags", FT_UINT32, BASE_HEX, NULL, 0x0,
-                       NULL, HFILL }},
+        { &hf_flags,
+        { "Flags", "sss.flags", FT_UINT32, BASE_HEX, NULL, 0x0,
+          NULL, HFILL }},
 
-               { &hf_context,
-               { "Context",            "sss.context", FT_UINT32, BASE_HEX, NULL, 0x0,
-                       NULL, HFILL }},
+        { &hf_context,
+        { "Context", "sss.context", FT_UINT32, BASE_HEX, NULL, 0x0,
+          NULL, HFILL }},
 
-               { &hf_frag_handle,
-               { "Fragment Handle",            "sss.frag_handle", FT_UINT32, BASE_HEX, NULL, 0x0,
-                       NULL, HFILL }},
+        { &hf_frag_handle,
+        { "Fragment Handle", "sss.frag_handle", FT_UINT32, BASE_HEX, NULL, 0x0,
+          NULL, HFILL }},
 
-               { &hf_length,
-               { "Length",             "sss.length", FT_UINT32, BASE_DEC, NULL, 0x0,
-                       NULL, HFILL }},
+        { &hf_length,
+        { "Length", "sss.length", FT_UINT32, BASE_DEC, NULL, 0x0,
+          NULL, HFILL }},
 
         { &hf_verb,
         { "Verb",    "sss.verb",
@@ -814,13 +817,13 @@ proto_register_sss(void)
           FT_STRING,    BASE_NONE,   NULL,   0x0,
           NULL, HFILL }},
 
-               { &hf_sss_version,
-               { "SecretStore Protocol Version",               "sss.version", FT_UINT32, BASE_HEX, NULL, 0x0,
-                       NULL, HFILL }},
+        { &hf_sss_version,
+        { "SecretStore Protocol Version", "sss.version", FT_UINT32, BASE_HEX, NULL, 0x0,
+          NULL, HFILL }},
 
         { &hf_return_code,
-               { "Return Code",                "sss.return_code", FT_UINT32, BASE_HEX, VALS(sss_errors_enum), 0x0,
-                       NULL, HFILL }},
+        { "Return Code", "sss.return_code", FT_UINT32, BASE_HEX, VALS(sss_errors_enum), 0x0,
+          NULL, HFILL }},
 
         { &hf_enc_cred,
         { "Encrypted Credential",    "sss.enc_cred",
@@ -930,12 +933,12 @@ proto_register_sss(void)
 
     };
 
-       static gint *ett[] = {
-               &ett_sss,
-       };
-       /*module_t *sss_module;*/
+        static gint *ett[] = {
+            &ett_sss,
+        };
+        /*module_t *sss_module;*/
 
-       proto_sss = proto_register_protocol("Novell SecretStore Services", "SSS", "sss");
-       proto_register_field_array(proto_sss, hf_sss, array_length(hf_sss));
-       proto_register_subtree_array(ett, array_length(ett));
+        proto_sss = proto_register_protocol("Novell SecretStore Services", "SSS", "sss");
+        proto_register_field_array(proto_sss, hf_sss, array_length(hf_sss));
+        proto_register_subtree_array(ett, array_length(ett));
 }
index d1085758b8f331c67834baf7cd4af61fb21e478f..7435a7fdbeaf685aaf4234ea8b2a750b24f42745 100644 (file)
@@ -2242,13 +2242,9 @@ dissect_rpc_message(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
                 * AUTH_GSSAPI procname.
                 */
                if (flavor == FLAVOR_AUTHGSSAPI_MSG) {
-                       procname = (char *)match_strval(gss_proc, rpc_authgssapi_proc);
+                       procname = (char *)val_to_str_const(gss_proc, rpc_authgssapi_proc, "(null)");
                }
 
-               /* Don't pass NULL string pointers to the format routines below */
-               if (!procname)
-                       procname = "(null)";
-
                rpc_prog_key.prog = prog;
                if ((rpc_prog = g_hash_table_lookup(rpc_progs,&rpc_prog_key)) == NULL) {
                        proto = NULL;
index bac2d2cc8437d50b1b1412736189ab68476e06d1..4f07705851abc787d30bbc189d3a1004f6efc466 100644 (file)
@@ -873,10 +873,9 @@ dissect_parameter_group(tvbuff_t *tvb, int offset, proto_tree *tree,
                    val_to_str(param_type, param_vals,
                      "Unknown parameter type (0x%02x)"));
                param_tree = proto_item_add_subtree(ti, ett_ses_param);
-               param_str = match_strval(param_type, param_vals);
+               param_str = val_to_str_const(param_type, param_vals, "Unknown");
                proto_tree_add_text(param_tree, tvb, offset, 1,
-                   "Parameter type: %s",
-                   param_str != NULL ? param_str : "Unknown");
+                   "Parameter type: %s", param_str);
                offset++;
                pg_len--;
                param_len = get_item_len(tvb, offset, &len_len);
@@ -952,10 +951,9 @@ dissect_parameters(tvbuff_t *tvb, int offset, guint16 len, proto_tree *tree,
                    val_to_str(param_type, param_vals,
                      "Unknown parameter type (0x%02x)"));
                param_tree = proto_item_add_subtree(ti, ett_ses_param);
-               param_str = match_strval(param_type, param_vals);
+               param_str = val_to_str_const(param_type, param_vals, "Unknown");
                proto_tree_add_text(param_tree, tvb, offset, 1,
-                   "Parameter type: %s",
-                   param_str != NULL ? param_str : "Unknown");
+                   "Parameter type: %s", param_str);
                offset++;
                len--;
                param_len = get_item_len(tvb, offset, &len_len);
@@ -1136,22 +1134,22 @@ dissect_spdu(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree,
                guint32 ses_id = 0;
 
                /* Use conversation index as segment id */
-               conversation  = find_conversation (pinfo->fd->num, 
-                                                  &pinfo->src, &pinfo->dst, pinfo->ptype, 
+               conversation  = find_conversation (pinfo->fd->num,
+                                                  &pinfo->src, &pinfo->dst, pinfo->ptype,
                                                   pinfo->srcport, pinfo->destport, 0);
                if (conversation != NULL) {
                        ses_id = conversation->index;
                }
                fragment_len = tvb_reported_length_remaining (tvb, offset);
-               ti = proto_tree_add_item (ses_tree, hf_ses_segment_data, tvb, offset, 
+               ti = proto_tree_add_item (ses_tree, hf_ses_segment_data, tvb, offset,
                                          fragment_len, FALSE);
                proto_item_append_text (ti, " (%d byte%s)", fragment_len, plurality (fragment_len, "", "s"));
-               frag_msg = fragment_add_seq_next (tvb, offset, pinfo, 
+               frag_msg = fragment_add_seq_next (tvb, offset, pinfo,
                                                  ses_id, ses_fragment_table,
                                                  ses_reassembled_table, fragment_len,
                                                  (enclosure_item_flags & END_SPDU) ? FALSE : TRUE);
-               next_tvb = process_reassembled_data (tvb, offset, pinfo, "Reassembled SES", 
-                                                    frag_msg, &ses_frag_items, NULL, 
+               next_tvb = process_reassembled_data (tvb, offset, pinfo, "Reassembled SES",
+                                                    frag_msg, &ses_frag_items, NULL,
                                                     (enclosure_item_flags & END_SPDU) ? tree : ses_tree);
 
                has_user_information = TRUE;
@@ -1968,9 +1966,9 @@ dissect_ses_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree)
                type = tvb_get_guint8(tvb, offset+2);
                /* check SPDU type */
                if (match_strval(type, ses_vals) == NULL)
-                       {
-                               return FALSE;  /* no, it isn't a session PDU */
-                       }
+               {
+                       return FALSE;  /* no, it isn't a session PDU */
+               }
        }
 
        /* some Siemens SIMATIC protocols also use COTP, and shouldn't be
index e9c180ad5532bbfdccc4ecaa49469745f6ff4ed4..2d3f11b8be8636539799df4e8a60ad9457c2e39c 100644 (file)
@@ -69,8 +69,6 @@ static dissector_table_t spp_socket_dissector_table;
 static const char*
 spp_conn_ctrl(guint8 ctrl)
 {
-       const char *p;
-
        static const value_string conn_vals[] = {
                { 0x00,                        "Data, No Ack Required" },
                { SPP_EOM,                     "End-of-Message" },
@@ -82,14 +80,7 @@ spp_conn_ctrl(guint8 ctrl)
                { 0x00,                        NULL }
        };
 
-       p = match_strval((ctrl & 0xf0), conn_vals );
-
-       if (p) {
-               return p;
-       }
-       else {
-               return "Unknown";
-       }
+       return val_to_str_const((ctrl & 0xf0), conn_vals, "Unknown");
 }
 
 static const char*