From 4e87f6c01a7bd0dc29959492e758eb6fae0a9fc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stig=20Bj=C3=B8rlykke?= Date: Tue, 9 Jan 2018 13:28:17 +0100 Subject: proto: Small code cleanup in proto_register_protocol MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Remove unneeded assignments - Fix some comments and whitespace Change-Id: I79de66315db29fe7c59fc18f3b3b464ac55121c8 Reviewed-on: https://code.wireshark.org/review/25221 Petri-Dish: Stig Bjørlykke Tested-by: Petri Dish Buildbot Reviewed-by: Anders Broman --- epan/proto.c | 39 ++++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 21 deletions(-) (limited to 'epan') diff --git a/epan/proto.c b/epan/proto.c index a89c901ccb..51a402358e 100644 --- a/epan/proto.c +++ b/epan/proto.c @@ -6442,9 +6442,7 @@ proto_register_protocol(const char *name, const char *short_name, const char *filter_name) { protocol_t *protocol; - const protocol_t *existing_protocol = NULL; header_field_info *hfinfo; - int proto_id; guint i; gchar c; gboolean found_invalid; @@ -6457,15 +6455,13 @@ proto_register_protocol(const char *name, const char *short_name, * protocol with the same name. */ - existing_protocol = (const protocol_t *)g_hash_table_lookup(proto_names, name); - if (existing_protocol != NULL) { + if (g_hash_table_lookup(proto_names, name)) { /* g_error will terminate the program */ g_error("Duplicate protocol name \"%s\"!" " This might be caused by an inappropriate plugin or a development error.", name); } - existing_protocol = (const protocol_t *)g_hash_table_lookup(proto_short_names, short_name); - if (existing_protocol != NULL) { + if (g_hash_table_lookup(proto_short_names, short_name)) { g_error("Duplicate protocol short_name \"%s\"!" " This might be caused by an inappropriate plugin or a development error.", short_name); } @@ -6482,27 +6478,28 @@ proto_register_protocol(const char *name, const char *short_name, " Allowed are lower characters, digits, '-', '_' and '.'." " This might be caused by an inappropriate plugin or a development error.", filter_name); } - existing_protocol = (const protocol_t *)g_hash_table_lookup(proto_filter_names, filter_name); - if (existing_protocol != NULL) { + + if (g_hash_table_lookup(proto_filter_names, filter_name)) { g_error("Duplicate protocol filter_name \"%s\"!" " This might be caused by an inappropriate plugin or a development error.", filter_name); } - /* Add this protocol to the list of known protocols; the list - is sorted by protocol short name. */ + /* + * Add this protocol to the list of known protocols; + * the list is sorted by protocol short name. + */ protocol = g_new(protocol_t, 1); protocol->name = name; protocol->short_name = short_name; protocol->filter_name = filter_name; - /*protocol->fields = g_ptr_array_new();*/ - /* Delegate until actually needed and use g_ptr_array_sized_new*/ - protocol->fields = NULL; + protocol->fields = NULL; /* Delegate until actually needed */ protocol->is_enabled = TRUE; /* protocol is enabled by default */ protocol->enabled_by_default = TRUE; /* see previous comment */ protocol->can_toggle = TRUE; protocol->parent_proto_id = -1; protocol->heur_list = NULL; - /* list will be sorted later by name, when all protocols completed registering */ + + /* List will be sorted later by name, when all protocols completed registering */ protocols = g_list_prepend(protocols, protocol); g_hash_table_insert(proto_names, (gpointer)name, protocol); g_hash_table_insert(proto_filter_names, (gpointer)filter_name, protocol); @@ -6518,11 +6515,10 @@ proto_register_protocol(const char *name, const char *short_name, hfinfo->bitmask = 0; hfinfo->ref_type = HF_REF_TYPE_NONE; hfinfo->blurb = NULL; - hfinfo->parent = -1; /* this field differentiates protos and fields */ + hfinfo->parent = -1; /* This field differentiates protos and fields */ - proto_id = proto_register_field_init(hfinfo, hfinfo->parent); - protocol->proto_id = proto_id; - return proto_id; + protocol->proto_id = proto_register_field_init(hfinfo, hfinfo->parent); + return protocol->proto_id; } int @@ -6564,7 +6560,7 @@ proto_register_protocol_in_name_only(const char *name, const char *short_name, c protocol->name = name; protocol->short_name = short_name; protocol->filter_name = filter_name; - protocol->fields = NULL; + protocol->fields = NULL; /* Delegate until actually needed */ /* Enabling and toggling is really determined by parent protocol, but provide default values here */ @@ -6574,7 +6570,8 @@ proto_register_protocol_in_name_only(const char *name, const char *short_name, c protocol->parent_proto_id = parent_proto; protocol->heur_list = NULL; - /* list will be sorted later by name, when all protocols completed registering */ + + /* List will be sorted later by name, when all protocols completed registering */ pino_protocols = g_list_prepend(pino_protocols, protocol); /* Here we allocate a new header_field_info struct */ @@ -6590,7 +6587,7 @@ proto_register_protocol_in_name_only(const char *name, const char *short_name, c hfinfo->bitmask = 0; hfinfo->ref_type = HF_REF_TYPE_NONE; hfinfo->blurb = NULL; - hfinfo->parent = -1; /* this field differentiates protos and fields */ + hfinfo->parent = -1; /* This field differentiates protos and fields */ protocol->proto_id = proto_register_field_init(hfinfo, hfinfo->parent); return protocol->proto_id; -- cgit v1.2.3