[PATCH 5/8] wireshark: Don't special case retval of get_program_data() in dissect_libvirt_message()

Michal Privoznik via Devel posted 8 patches 2 weeks ago
[PATCH 5/8] wireshark: Don't special case retval of get_program_data() in dissect_libvirt_message()
Posted by Michal Privoznik via Devel 2 weeks ago
From: Michal Privoznik <mprivozn@redhat.com>

The get_program_data() function returns a pointer (in this
specific case to an array of procedure strings) which, if
non-NULL is then passed val_to_str(). Well, if val_to_str() sees
NULL it is treated gracefully, i.e. like if the numeric value
'proc' wasn't found in the array.

Therefore, there's no need to special case call to
col_append_fstr(). Both result into the same behaviour.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 tools/wireshark/src/packet-libvirt.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/tools/wireshark/src/packet-libvirt.c b/tools/wireshark/src/packet-libvirt.c
index af14c6bed7..6c729801d4 100644
--- a/tools/wireshark/src/packet-libvirt.c
+++ b/tools/wireshark/src/packet-libvirt.c
@@ -469,11 +469,7 @@ dissect_libvirt_message(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
                  val_to_str(prog, program_strings, "%x"));
 
     vs = get_program_data(prog, VIR_PROGRAM_PROCSTRINGS);
-    if (vs == NULL) {
-        col_append_fstr(pinfo->cinfo, COL_INFO, " Proc=%d", proc);
-    } else {
-        col_append_fstr(pinfo->cinfo, COL_INFO, " Proc=%s", val_to_str(proc, vs, "%d"));
-    }
+    col_append_fstr(pinfo->cinfo, COL_INFO, " Proc=%s", val_to_str(proc, vs, "%d"));
 
     col_append_fstr(pinfo->cinfo, COL_INFO, " Type=%s Serial=%u Status=%s",
                     val_to_str(type, type_strings, "%d"), serial,
-- 
2.49.1
Re: [PATCH 5/8] wireshark: Don't special case retval of get_program_data() in dissect_libvirt_message()
Posted by Peter Krempa via Devel 1 week, 6 days ago
On Tue, Oct 14, 2025 at 08:31:44 +0200, Michal Privoznik via Devel wrote:
> From: Michal Privoznik <mprivozn@redhat.com>
> 
> The get_program_data() function returns a pointer (in this
> specific case to an array of procedure strings) which, if
> non-NULL is then passed val_to_str(). Well, if val_to_str() sees
> NULL it is treated gracefully, i.e. like if the numeric value
> 'proc' wasn't found in the array.
> 
> Therefore, there's no need to special case call to
> col_append_fstr(). Both result into the same behaviour.
> 
> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
> ---
>  tools/wireshark/src/packet-libvirt.c | 6 +-----
>  1 file changed, 1 insertion(+), 5 deletions(-)

Reviewed-by: Peter Krempa <pkrempa@redhat.com>