Wireshark mailing list archives

Re: Problem with val_to_str inside BASE_CUSTOM callback function


From: Guy Harris <guy () alum mit edu>
Date: Fri, 21 Oct 2016 10:47:12 -0700

On Oct 21, 2016, at 9:57 AM, Thomas Wiens <th.wiens () gmx de> wrote:

This happens only when calling val_to_str inside the callback function.
When outside, then all is Ok (getting formatted result string on failure).
When I'm calling try_val_to_str_idx with a non existing value, then I
get -1 as index and NULL as result as expected, so I guess the problem is:

wmem_strdup_printf(wmem_packet_scope(), fmt, val);

Is there a limitation when I'm using format callbacks,

Yes. You're limited to using wmem scopes that are active even if you're *not* in the middle of dissecting a packet; the 
callback is called when the result of a dissection is being displayed or used for a custom column, and that's not in 
the middle of dissecting a packet.

Unfortunately, I don't think there's a scope for this, so you'd either have to use NULL as the scope and explicitly 
free the string when you're done with it, or use try_val_to_str() and deal with a NULL return (nothing matches) 
yourself.
___________________________________________________________________________
Sent via:    Wireshark-dev mailing list <wireshark-dev () wireshark org>
Archives:    https://www.wireshark.org/lists/wireshark-dev
Unsubscribe: https://www.wireshark.org/mailman/options/wireshark-dev
             mailto:wireshark-dev-request () wireshark org?subject=unsubscribe


Current thread: