Don't assign to a proto_item* if the value won't be used:

Fixes Coverity 903,935,968,985,997,999,1024,1025,1134;
Remove unneeded #includes;
Do whitespace cleanup.

svn path=/trunk/; revision=37331
This commit is contained in:
Bill Meier 2011-05-20 15:44:25 +00:00
parent 4910bc142f
commit f3432a973c
9 changed files with 110 additions and 124 deletions

View File

@ -31,7 +31,6 @@
# include "config.h"
#endif
#include <stdlib.h>
#include <string.h>
#include <epan/packet.h>
#include <epan/expert.h>
@ -41,10 +40,10 @@
#include "packet-tcp.h"
typedef struct _fix_field {
int tag; /* FIX tag */
int hf_id;
int type; /* */
const void *table;
int tag; /* FIX tag */
int hf_id;
int type; /* */
const void *table;
} fix_field;
typedef struct _fix_parameter {
@ -92,8 +91,8 @@ static int fix_marker(tvbuff_t *tvb, int offset)
#include "packet-fix.h"
static void dissect_fix_init(void) {
/* TODO load xml def for private field */
/* TODO check that fix_fields is really sorted */
/* TODO load xml def for private field */
/* TODO check that fix_fields is really sorted */
}
static int
@ -101,15 +100,15 @@ tag_search(int key)
{
int lower = 0, upper = array_length(fix_fields) -1;
while (lower <= upper) {
int middle = (lower + upper) / 2;
int res = fix_fields[middle].tag;
if (res < key) {
lower = middle + 1;
} else if (res == key) {
return middle;
} else {
upper = middle - 1;
}
int middle = (lower + upper) / 2;
int res = fix_fields[middle].tag;
if (res < key) {
lower = middle + 1;
} else if (res == key) {
return middle;
} else {
upper = middle - 1;
}
}
return -1;
}
@ -274,8 +273,8 @@ dissect_fix_packet(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
if (check_col(pinfo->cinfo, COL_INFO)) {
const char *msg_type;
value = tvb_get_ephemeral_string(tvb, tag->value_offset, tag->value_len);
msg_type = str_to_str(value, messages_val, "FIX Message (%s)");
value = tvb_get_ephemeral_string(tvb, tag->value_offset, tag->value_len);
msg_type = str_to_str(value, messages_val, "FIX Message (%s)");
col_add_str(pinfo->cinfo, COL_INFO, msg_type);
}
@ -372,7 +371,7 @@ dissect_fix_packet(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
}
break;
default:
item = proto_tree_add_string(fix_tree, fix_fields[i].hf_id, tvb, field_offset, tag->field_len, value);
proto_tree_add_string(fix_tree, fix_fields[i].hf_id, tvb, field_offset, tag->field_len, value);
break;
}
}
@ -397,10 +396,10 @@ dissect_fix_packet(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
static guint
get_fix_pdu_len(packet_info *pinfo _U_, tvbuff_t *tvb, int offset)
{
int fix_len;
int fix_len;
fix_len = fix_header_len(tvb, offset);
return fix_len;
fix_len = fix_header_len(tvb, offset);
return fix_len;
}
/* ------------------------------------
@ -419,7 +418,7 @@ static void
dissect_fix_pdus(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
tcp_dissect_pdus(tvb, pinfo, tree, fix_desegment, FIX_MIN_LEN,
get_fix_pdu_len, dissect_fix_packet);
get_fix_pdu_len, dissect_fix_packet);
}
@ -450,19 +449,19 @@ dissect_fix_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
/* Register the protocol with Wireshark */
static void range_delete_fix_tcp_callback(guint32 port) {
dissector_delete_uint("tcp.port", port, fix_handle);
dissector_delete_uint("tcp.port", port, fix_handle);
}
static void range_add_fix_tcp_callback(guint32 port) {
dissector_add_uint("tcp.port", port, fix_handle);
dissector_add_uint("tcp.port", port, fix_handle);
}
static void fix_prefs(void)
{
range_foreach(fix_tcp_range, range_delete_fix_tcp_callback);
g_free(fix_tcp_range);
fix_tcp_range = range_copy(global_fix_tcp_range);
range_foreach(fix_tcp_range, range_add_fix_tcp_callback);
range_foreach(fix_tcp_range, range_delete_fix_tcp_callback);
g_free(fix_tcp_range);
fix_tcp_range = range_copy(global_fix_tcp_range);
range_foreach(fix_tcp_range, range_add_fix_tcp_callback);
}
/* this format is require because a script is used to build the C function
@ -475,25 +474,25 @@ proto_register_fix(void)
/* Setup list of header fields See Section 1.6.1 for details*/
static hf_register_info hf[] = {
{ &hf_fix_data,
{ "Continuation Data", "fix.data", FT_BYTES, BASE_NONE, NULL, 0x00,
{ "Continuation Data", "fix.data", FT_BYTES, BASE_NONE, NULL, 0x00,
NULL, HFILL }
},
{ &hf_fix_field_tag,
{ "Field Tag", "fix.field.tag", FT_UINT16, BASE_DEC, NULL, 0x0,
{ "Field Tag", "fix.field.tag", FT_UINT16, BASE_DEC, NULL, 0x0,
"Field length.", HFILL }},
{ &hf_fix_field_value,
{ "Field Value", "fix.field.value", FT_STRING, BASE_NONE, NULL, 0x0,
{ "Field Value", "fix.field.value", FT_STRING, BASE_NONE, NULL, 0x0,
NULL, HFILL }},
{ &hf_fix_checksum_good,
{ "Good Checksum", "fix.checksum_good", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
"True: checksum matches packet content; False: doesn't match content or not checked", HFILL }},
{ &hf_fix_checksum_good,
{ "Good Checksum", "fix.checksum_good", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
"True: checksum matches packet content; False: doesn't match content or not checked", HFILL }},
{ &hf_fix_checksum_bad,
{ "Bad Checksum", "fix.checksum_bad", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
"True: checksum doesn't match packet content; False: matches content or not checked", HFILL }},
{ &hf_fix_checksum_bad,
{ "Bad Checksum", "fix.checksum_bad", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
"True: checksum doesn't match packet content; False: matches content or not checked", HFILL }},
};
/* Setup protocol subtree array */
@ -511,7 +510,7 @@ proto_register_fix(void)
/* Register the protocol name and description */
proto_fix = proto_register_protocol("Financial Information eXchange Protocol",
"FIX", "fix");
"FIX", "fix");
/* Required function calls to register the header fields and subtrees used */
proto_register_field_array(proto_fix, hf, array_length(hf));
@ -520,10 +519,10 @@ proto_register_fix(void)
fix_module = prefs_register_protocol(proto_fix, fix_prefs);
prefs_register_bool_preference(fix_module, "desegment",
"Reassemble FIX messages spanning multiple TCP segments",
"Whether the FIX dissector should reassemble messages spanning multiple TCP segments."
" To use this option, you must also enable \"Allow subdissectors to reassemble TCP streams\" in the TCP protocol settings.",
&fix_desegment);
"Reassemble FIX messages spanning multiple TCP segments",
"Whether the FIX dissector should reassemble messages spanning multiple TCP segments."
" To use this option, you must also enable \"Allow subdissectors to reassemble TCP streams\" in the TCP protocol settings.",
&fix_desegment);
prefs_register_range_preference(fix_module, "tcp.port", "TCP Ports", "TCP Ports range", &global_fix_tcp_range, 65535);
@ -531,10 +530,6 @@ proto_register_fix(void)
}
/* If this dissector uses sub-dissector registration add a registration routine.
This format is required because a script is used to find these routines and
create the code that calls these routines.
*/
void
proto_reg_handoff_fix(void)
{

View File

@ -29,7 +29,7 @@
#endif
#include <ctype.h>
#include <glib.h>
#include <epan/packet.h>
#include <epan/addr_resolv.h>
#include <epan/strutil.h>
@ -561,7 +561,7 @@ static void dissect_imf(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
unknown_tree = proto_item_add_subtree(item, ett_imf_extension);
item = proto_tree_add_item(unknown_tree, hf_imf_extension_type, tvb, unknown_offset, start_offset - 1 - unknown_offset, FALSE);
proto_tree_add_item(unknown_tree, hf_imf_extension_type, tvb, unknown_offset, start_offset - 1 - unknown_offset, FALSE);
/* remove 2 bytes to take off the final CRLF to make things a little prettier */
item = proto_tree_add_item(unknown_tree, hf_imf_extension_value, tvb, start_offset, end_offset - start_offset - 2, FALSE);
@ -604,7 +604,7 @@ static void dissect_imf(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
if(content_type_str && media_type_dissector_table) {
void* pd_save;
pd_save = pinfo->private_data;
pinfo->private_data = parameters;
pinfo->private_data = parameters;
next_tvb = tvb_new_subset_remaining(tvb, end_offset);

View File

@ -34,9 +34,8 @@
# include "config.h"
#endif
#include <glib.h>
#include <epan/packet.h>
#include <epan/emem.h>
#include <epan/expert.h>
@ -207,8 +206,8 @@ static void dissect_miop (tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree
ep_strbuf_append_printf(flags_strbuf, "%s%s",
flags_strbuf->len ? ", " : "", "last message");
}
ti = proto_tree_add_uint_format_value(miop_tree, hf_miop_flags, tvb, offset, 1,
flags, "0x%02x (%s)", flags, flags_strbuf->str);
proto_tree_add_uint_format_value(miop_tree, hf_miop_flags, tvb, offset, 1,
flags, "0x%02x (%s)", flags, flags_strbuf->str);
offset++;
proto_tree_add_item(miop_tree, hf_miop_packet_length, tvb, offset, 2, little_endian);
offset += 2;

View File

@ -4957,7 +4957,7 @@ dissect_v9_v10_template_fields(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree
} else {
int fields_type_pen = pen_to_type_hf_list(pen);
if (fields_type_pen != TF_NO_VENDOR_INFO) {
ti = proto_tree_add_item(field_tree, *v10_template_type_hf_list[fields_type_pen],
proto_tree_add_item(field_tree, *v10_template_type_hf_list[fields_type_pen],
tvb, offset, 2, ENC_BIG_ENDIAN);
proto_item_append_text(field_item, ": %s",
val_to_str_ext(type&0x7fff, v10_template_type_vse_list[fields_type_pen], "Unknown(%d)"));

View File

@ -29,9 +29,8 @@
# include "config.h"
#endif
#include <glib.h>
#include <epan/packet.h>
#include <prefs.h>
#define NSIP_DEBUG 0
@ -462,7 +461,7 @@ static proto_item *
decode_ip_elements(nsip_ip_element_info_t *element, nsip_ie_t *ie, build_info_t *bi, int ie_start_offset) {
int i;
int num_elements = ie->value_length / element->total_length;
proto_item *tf, *ti = NULL;
proto_item *tf;
proto_tree *field_tree;
tf = proto_tree_add_text(bi->nsip_tree, bi->tvb, ie_start_offset,
@ -472,7 +471,7 @@ decode_ip_elements(nsip_ip_element_info_t *element, nsip_ie_t *ie, build_info_t
field_tree = proto_item_add_subtree(tf, ett_nsip_ip_element_list);
for (i = 0; i < num_elements; i++) {
ti = decode_ip_element(element, bi, field_tree);
decode_ip_element(element, bi, field_tree);
}
return tf;
}

View File

@ -32,8 +32,8 @@
# include "config.h"
#endif
#include <glib.h>
#include <epan/packet.h>
#include <epan/etypes.h>
#include <epan/addr_resolv.h>
#include "packet-ip.h"
@ -143,8 +143,8 @@ dissect_pflog(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
if (hdrlen < MIN_PFLOG_HDRLEN) {
if (tree) {
ti = proto_tree_add_protocol_format(tree, proto_pflog, tvb, 0,
hdrlen, "PF Log invalid header length (%u)", hdrlen);
proto_tree_add_protocol_format(tree, proto_pflog, tvb, 0,
hdrlen, "PF Log invalid header length (%u)", hdrlen);
}
if (check_col(pinfo->cinfo, COL_INFO)) {
col_prepend_fstr(pinfo->cinfo, COL_INFO, "Invalid header length %u",
@ -253,7 +253,7 @@ proto_register_pflog(void)
static gint *ett[] = { &ett_pflog };
proto_pflog = proto_register_protocol("OpenBSD Packet Filter log file",
"PFLOG", "pflog");
"PFLOG", "pflog");
proto_register_field_array(proto_pflog, hf, array_length(hf));
proto_register_subtree_array(ett, array_length(ett));
}
@ -373,8 +373,8 @@ proto_register_old_pflog(void)
static gint *ett[] = { &ett_old_pflog };
proto_old_pflog = proto_register_protocol(
"OpenBSD Packet Filter log file, pre 3.4",
"PFLOG-OLD", "pflog-old");
"OpenBSD Packet Filter log file, pre 3.4",
"PFLOG-OLD", "pflog-old");
proto_register_field_array(proto_old_pflog, hf, array_length(hf));
proto_register_subtree_array(ett, array_length(ett));
}

View File

@ -43,11 +43,10 @@
# include "config.h"
#endif
#include <stdio.h>
#include <string.h>
#include <glib.h>
#include <epan/packet.h>
#include <epan/emem.h>
#include <epan/conversation.h>
#include <epan/strutil.h>
@ -574,7 +573,7 @@ rtmpt_get_amf_param(tvbuff_t *tvb, gint offset, gint param, const gchar *prop)
iStringLength = tvb_get_ntohs(tvb, offset+2+iPropLength+1);
if (remain<2+iPropLength+3+iStringLength) break;
return tvb_get_ephemeral_string(tvb, offset+2+iPropLength+3, iStringLength);
}
@ -628,7 +627,7 @@ rtmpt_get_packet_desc(tvbuff_t *tvb, guint32 offset, guint32 remain, rtmpt_conv_
if (tp->len>=5 && remain>=5) {
*deschasopcode = TRUE;
return ep_strdup_printf("%s %d,%s",
val_to_str(tp->cmd, rtmpt_opcode_vals, "Unknown (0x%01x)"),
val_to_str(tp->cmd, rtmpt_opcode_vals, "Unknown (0x%01x)"),
tvb_get_ntohl(tvb, offset),
val_to_str(tvb_get_guint8(tvb, offset+4), rtmpt_limit_vals, "Unknown (%d)"));
}
@ -945,7 +944,7 @@ dissect_rtmpt_body_command(tvbuff_t *tvb, gint offset, proto_tree *rtmpt_tree, g
proto_tree_add_item(val_tree, hf_rtmpt_amf_longstringlength, tvb, iValueOffset-iValueExtra+1, 4, FALSE);
}
if (iValueLength>0 && hfvalue!=-1) {
ti = proto_tree_add_item(val_tree, hfvalue, tvb, iValueOffset, iValueLength, FALSE);
proto_tree_add_item(val_tree, hfvalue, tvb, iValueOffset, iValueLength, FALSE);
}
}

View File

@ -60,11 +60,8 @@
# include "config.h"
#endif
#include <glib.h>
#include <epan/packet.h>
#include <stdio.h>
#include "packet-rtp.h"
#include <epan/rtp_pt.h>
#include <epan/conversation.h>
@ -119,19 +116,19 @@ static gint ett_rtp_fragment = -1;
static gint ett_rtp_fragments = -1;
static const fragment_items rtp_fragment_items = {
&ett_rtp_fragment,
&ett_rtp_fragments,
&hf_rtp_fragments,
&hf_rtp_fragment,
&hf_rtp_fragment_overlap,
&hf_rtp_fragment_overlap_conflict,
&hf_rtp_fragment_multiple_tails,
&hf_rtp_fragment_too_long_fragment,
&hf_rtp_fragment_error,
&hf_rtp_fragment_count,
&hf_rtp_reassembled_in,
&hf_rtp_reassembled_length,
"RTP fragments"
&ett_rtp_fragment,
&ett_rtp_fragments,
&hf_rtp_fragments,
&hf_rtp_fragment,
&hf_rtp_fragment_overlap,
&hf_rtp_fragment_overlap_conflict,
&hf_rtp_fragment_multiple_tails,
&hf_rtp_fragment_too_long_fragment,
&hf_rtp_fragment_error,
&hf_rtp_fragment_count,
&hf_rtp_reassembled_in,
&hf_rtp_reassembled_length,
"RTP fragments"
};
static dissector_handle_t rtp_handle;
@ -1358,7 +1355,7 @@ dissect_rtp( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree )
proto_tree_add_boolean( rtp_tree, hf_rtp_marker, tvb, offset,
1, octet2 );
item = proto_tree_add_uint_format( rtp_tree, hf_rtp_payload_type, tvb,
proto_tree_add_uint_format( rtp_tree, hf_rtp_payload_type, tvb,
offset, 1, octet2, "Payload type: %s (%u)",
payload_type_str ? payload_type_str : val_to_str_ext( payload_type, &rtp_payload_type_vals_ext,"Unknown"),
payload_type);

View File

@ -30,14 +30,11 @@
#endif /* HAVEHCONFIG_H */
#include <string.h>
#include <stdlib.h>
#include <glib.h>
#include <gmodule.h>
#include <epan/proto.h>
#include <epan/packet.h>
#include <epan/prefs.h>
#include <epan/expert.h>
#include <epan/uat.h>
/* We require libgcrpyt in order to decrypt ZigBee packets. Without it the best
@ -144,7 +141,7 @@ static void* uat_key_record_copy_cb(void* n, const void* o, size_t siz _U_) {
const uat_key_record_t* old_key = (uat_key_record_t *)o;
if (old_key->string) {
new_key->string = g_strdup(old_key->string);
new_key->string = g_strdup(old_key->string);
} else {
new_key->string = NULL;
}
@ -214,33 +211,33 @@ static GSList *zbee_pc_keyring = NULL;
void zbee_security_register(module_t *zbee_prefs, int proto)
{
static hf_register_info hf[] = {
{ &hf_zbee_sec_key_id,
{ "Key Id", "zbee.sec.key", FT_UINT8, BASE_HEX, VALS(zbee_sec_key_names),
ZBEE_SEC_CONTROL_KEY, NULL, HFILL }},
{ &hf_zbee_sec_key_id,
{ "Key Id", "zbee.sec.key", FT_UINT8, BASE_HEX, VALS(zbee_sec_key_names),
ZBEE_SEC_CONTROL_KEY, NULL, HFILL }},
{ &hf_zbee_sec_nonce,
{ "Extended Nonce", "zbee.sec.ext_nonce", FT_BOOLEAN, 8, NULL, ZBEE_SEC_CONTROL_NONCE,
NULL, HFILL }},
{ &hf_zbee_sec_nonce,
{ "Extended Nonce", "zbee.sec.ext_nonce", FT_BOOLEAN, 8, NULL, ZBEE_SEC_CONTROL_NONCE,
NULL, HFILL }},
{ &hf_zbee_sec_counter,
{ "Frame Counter", "zbee.sec.counter", FT_UINT32, BASE_DEC, NULL, 0x0,
NULL, HFILL }},
{ &hf_zbee_sec_counter,
{ "Frame Counter", "zbee.sec.counter", FT_UINT32, BASE_DEC, NULL, 0x0,
NULL, HFILL }},
{ &hf_zbee_sec_src64,
{ "Extended Source", "zbee.sec.src64", FT_EUI64, BASE_NONE, NULL, 0x0,
NULL, HFILL }},
{ &hf_zbee_sec_src64,
{ "Extended Source", "zbee.sec.src64", FT_EUI64, BASE_NONE, NULL, 0x0,
NULL, HFILL }},
{ &hf_zbee_sec_key_seqno,
{ "Key Sequence Number", "zbee.sec.key_seqno", FT_UINT8, BASE_DEC, NULL, 0x0,
NULL, HFILL }},
{ &hf_zbee_sec_key_seqno,
{ "Key Sequence Number", "zbee.sec.key_seqno", FT_UINT8, BASE_DEC, NULL, 0x0,
NULL, HFILL }},
{ &hf_zbee_sec_mic,
{ "Message Integrity Code", "zbee.sec.mic", FT_BYTES, BASE_NONE, NULL, 0x0,
NULL, HFILL }},
{ &hf_zbee_sec_mic,
{ "Message Integrity Code", "zbee.sec.mic", FT_BYTES, BASE_NONE, NULL, 0x0,
NULL, HFILL }},
{ &hf_zbee_sec_key_origin,
{ "Key Origin", "zbee.sec.key.origin", FT_FRAMENUM, BASE_NONE, NULL, 0x0,
NULL, HFILL }}
{ &hf_zbee_sec_key_origin,
{ "Key Origin", "zbee.sec.key.origin", FT_FRAMENUM, BASE_NONE, NULL, 0x0,
NULL, HFILL }}
};
static gint *ett[] = {
@ -249,14 +246,14 @@ void zbee_security_register(module_t *zbee_prefs, int proto)
};
static uat_field_t key_uat_fields[] = {
UAT_FLD_CSTRING(uat_key_records, string, "Key",
"A 16-byte key in hexadecimal with optional dash-,\n"
"colon-, or space-separator characters, or a\n"
"a 16-character string in double-quotes."),
UAT_FLD_VS(uat_key_records, byte_order, "Byte Order", byte_order_vals,
"Byte order of key."),
UAT_FLD_LSTRING(uat_key_records, label, "Label", "User label for key."),
UAT_END_FIELDS
UAT_FLD_CSTRING(uat_key_records, string, "Key",
"A 16-byte key in hexadecimal with optional dash-,\n"
"colon-, or space-separator characters, or a\n"
"a 16-character string in double-quotes."),
UAT_FLD_VS(uat_key_records, byte_order, "Byte Order", byte_order_vals,
"Byte order of key."),
UAT_FLD_LSTRING(uat_key_records, label, "Label", "User label for key."),
UAT_END_FIELDS
};
/* If no prefs module was supplied, register our own. */
@ -294,7 +291,7 @@ void zbee_security_register(module_t *zbee_prefs, int proto)
proto_register_field_array(proto, hf, array_length(hf));
proto_register_subtree_array(ett, array_length(ett));
/* Register the init routine. */
/* Register the init routine. */
register_init_routine(proto_init_zbee_security);
} /* zbee_security_register */
@ -589,7 +586,7 @@ dissect_zbee_secure(tvbuff_t *tvb, packet_info *pinfo, proto_tree* tree, guint o
if (mic_len) {
/* Display the MIC. */
if (tree) {
ti = proto_tree_add_item(sec_tree, hf_zbee_sec_mic, tvb, (gint)(tvb_length(tvb)-mic_len),
proto_tree_add_item(sec_tree, hf_zbee_sec_mic, tvb, (gint)(tvb_length(tvb)-mic_len),
mic_len, ENC_BIG_ENDIAN);
}
}