diff options
author | Guy Harris <guy@alum.mit.edu> | 2020-05-03 13:04:49 -0700 |
---|---|---|
committer | Guy Harris <gharris@sonic.net> | 2020-05-03 20:45:29 +0000 |
commit | bd963200cef84df076af8e8b169fc9af0edbd2d8 (patch) | |
tree | d1afa9e717bcf9c0f545ff96ea83ef5aca01cce7 /ui | |
parent | 90fdb71bf6cb22db6728a88f6a61ea44d9779f71 (diff) |
Clean up some issues with get_iface_list_string().
Remove an assignment of NULL to a variable when it's in a branch of code
where the variable's already known to be NULL. Found by PVS-Studio.
Pull get_display_name_for_interface() into the one place it's used.
That:
allows us to eliminate a test as, inside the loop where it's called,
the loop index is what's passed to it, and the loop tests whether
it's in range, so the test will never fail;
means we just set interface_opts once, for both of the places it's
used.
Then we fix that code so that it sets interface_opts->descr to a
generated descriptive name if it *is* null, rather than if it's *not*
null.
That should clean up some issues found by 1) PVS-Studio and 2) me.
Change-Id: I4188ca8f5c7306477ef11117016691d1c9f0267f
Reviewed-on: https://code.wireshark.org/review/37082
Petri-Dish: Guy Harris <gharris@sonic.net>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <gharris@sonic.net>
Diffstat (limited to 'ui')
-rw-r--r-- | ui/capture_ui_utils.c | 43 |
1 files changed, 13 insertions, 30 deletions
diff --git a/ui/capture_ui_utils.c b/ui/capture_ui_utils.c index c03fc2a1e5..870b7b81a4 100644 --- a/ui/capture_ui_utils.c +++ b/ui/capture_ui_utils.c @@ -276,7 +276,6 @@ get_interface_descriptive_name(const char *if_name) } else { /* No, we don't have a user-supplied description; did we get one from the OS or libpcap? */ - descr = NULL; if_list = capture_interface_list(&err, NULL, NULL); if (if_list != NULL) { if_entry = if_list; @@ -463,30 +462,6 @@ get_if_name(const char *if_text) return if_name; } -/* Return a display name for the interface. - */ -static const char * -get_display_name_for_interface(capture_options *capture_opts, guint i) -{ - interface_options *interface_opts; - - if (i < capture_opts->ifaces->len) { - interface_opts = &g_array_index(capture_opts->ifaces, interface_options, i); - if (interface_opts->display_name) { - return interface_opts->display_name; - } - if (!interface_opts->display_name) { - if (interface_opts->descr && interface_opts->name) { - interface_opts->descr = get_interface_descriptive_name(interface_opts->name); - } - interface_opts->display_name = g_strdup(interface_opts->descr); - } - return interface_opts->display_name; - } else { - return NULL; - } -} - /* * Set the active DLT for a device appropriately. */ @@ -566,16 +541,24 @@ get_iface_list_string(capture_options *capture_opts, guint32 style) g_string_append_printf(iface_list_string, "and "); } } + + interface_options *interface_opts = &g_array_index(capture_opts->ifaces, interface_options, i); + if (style & IFLIST_QUOTE_IF_DESCRIPTION) g_string_append_printf(iface_list_string, "'"); - const gchar* name = get_display_name_for_interface(capture_opts, i); - g_string_append_printf(iface_list_string, "%s", name ? name : ""); + if (interface_opts->display_name == NULL) { + /* + * We don't have a display name; generate one. + */ + if (interface_opts->descr == NULL && interface_opts->name) { + interface_opts->descr = get_interface_descriptive_name(interface_opts->name); + } + interface_opts->display_name = g_strdup(interface_opts->descr); + } + g_string_append_printf(iface_list_string, "%s", interface_opts->display_name); if (style & IFLIST_QUOTE_IF_DESCRIPTION) g_string_append_printf(iface_list_string, "'"); if (style & IFLIST_SHOW_FILTER) { - interface_options *interface_opts; - - interface_opts = &g_array_index(capture_opts->ifaces, interface_options, i); if (interface_opts->cfilter != NULL && strlen(interface_opts->cfilter) > 0) { g_string_append_printf(iface_list_string, " (%s)", interface_opts->cfilter); |