Use try_val_to_str_ext() in print_uuid().

That's a much cleaner way of determining whether you found no matchin
bluetooth_uuid_vals_ext than checking whether val_to_str_ext_const()
returned the "use this if unknown" value.

It also lets us avoid a wmem_strdup().

Make print_numeric_uuid() and print_uuid() return const gchar *; there's
no reason for them *not* to be const, and that means we don't have to
throw away constness.

Change-Id: I62fb0b81c64c107dfea6c16ca8c5b9593f8f2a9d
Reviewed-on: https://code.wireshark.org/review/12126
Reviewed-by: Guy Harris <guy@alum.mit.edu>
This commit is contained in:
Guy Harris 2015-11-24 22:21:15 -08:00
parent b1230ba123
commit 1c7b949290
3 changed files with 24 additions and 13 deletions

View File

@ -1572,7 +1572,7 @@ get_uuid(tvbuff_t *tvb, gint offset, gint size)
return uuid;
}
gchar *
const gchar *
print_numeric_uuid(bluetooth_uuid_t *uuid)
{
if (!(uuid && uuid->size > 0))
@ -1601,29 +1601,40 @@ print_numeric_uuid(bluetooth_uuid_t *uuid)
return NULL;
}
gchar *
const gchar *
print_uuid(bluetooth_uuid_t *uuid)
{
gchar *description;
const gchar *description;
if (uuid->bt_uuid) {
gchar *name;
const gchar *name;
name = wmem_strdup(wmem_packet_scope(), val_to_str_ext_const(uuid->bt_uuid, &bluetooth_uuid_vals_ext, "Unknown"));
if (strcmp(name , "Unknown"))
/*
* Known UUID?
*/
name = try_val_to_str_ext(uuid->bt_uuid, &bluetooth_uuid_vals_ext);
if (name != NULL) {
/*
* Yes. This string is part of the value_string_ext table,
* so we don't have to make a copy.
*/
return name;
}
/*
* No - fall through to try looking it up.
*/
}
description = print_numeric_uuid(uuid);
if (description) {
description = (gchar *) wmem_tree_lookup_string(bluetooth_uuids, description, 0);
description = (const gchar *) wmem_tree_lookup_string(bluetooth_uuids, description, 0);
if (description)
return description;
}
return (gchar *) "Unknown";
return "Unknown";
}
static bluetooth_data_t *

View File

@ -269,8 +269,8 @@ extern gint dissect_bd_addr(gint hf_bd_addr, packet_info *pinfo, proto_tree *tre
guint32 interface_id, guint32 adapter_id, guint8 *bdaddr);
extern bluetooth_uuid_t get_uuid(tvbuff_t *tvb, gint offset, gint size);
WS_DLL_PUBLIC gchar *print_uuid(bluetooth_uuid_t *uuid);
WS_DLL_PUBLIC gchar *print_numeric_uuid(bluetooth_uuid_t *uuid);
WS_DLL_PUBLIC const gchar *print_uuid(bluetooth_uuid_t *uuid);
WS_DLL_PUBLIC const gchar *print_numeric_uuid(bluetooth_uuid_t *uuid);
extern void save_local_device_name_from_eir_ad(tvbuff_t *tvb, gint offset,
packet_info *pinfo, guint8 size, bluetooth_data_t *bluetooth_data);

View File

@ -1993,7 +1993,7 @@ dissect_protocol_descriptor_list(proto_tree *next_tree, tvbuff_t *tvb,
list_offset = offset;
i_protocol = 1;
while (list_offset - offset < size) {
gchar *uuid_str;
const gchar *uuid_str;
feature_item = proto_tree_add_none_format(next_tree, hf_sdp_protocol_item, tvb, list_offset, 0, "Protocol #%u", i_protocol);
feature_tree = proto_item_add_subtree(feature_item, ett_btsdp_protocol);
@ -2149,7 +2149,7 @@ dissect_sdp_type(proto_tree *tree, packet_info *pinfo, tvbuff_t *tvb,
guint32 value;
guint64 value_64;
bluetooth_uuid_t uuid;
gchar *uuid_str;
const gchar *uuid_str;
gint length;
gint protocol_order;
wmem_strbuf_t *info_buf;