diff options
author | Guy Harris <guy@alum.mit.edu> | 2015-11-24 22:21:15 -0800 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2015-11-25 06:21:40 +0000 |
commit | 1c7b9492906835e81879f93fab940077aeab8dae (patch) | |
tree | a85202a77b5e9e04fa15c22e2b128676619a941f /epan/dissectors/packet-bluetooth.c | |
parent | b1230ba123699549770d0015a68e43108351eb52 (diff) |
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>
Diffstat (limited to 'epan/dissectors/packet-bluetooth.c')
-rw-r--r-- | epan/dissectors/packet-bluetooth.c | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/epan/dissectors/packet-bluetooth.c b/epan/dissectors/packet-bluetooth.c index 8f524537c2..cd11d2a50e 100644 --- a/epan/dissectors/packet-bluetooth.c +++ b/epan/dissectors/packet-bluetooth.c @@ -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; - - name = wmem_strdup(wmem_packet_scope(), val_to_str_ext_const(uuid->bt_uuid, &bluetooth_uuid_vals_ext, "Unknown")); - - if (strcmp(name , "Unknown")) + const gchar *name; + + /* + * 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 * |