Huge thanks to our Platinum Members Endace and LiveAction,
and our Silver Member Veeam, for supporting the Wireshark Foundation and project.

Wireshark-dev: Re: [Wireshark-dev] Problem with val_to_str inside BASE_CUSTOM callback function

From: Jaap Keuter <jaap.keuter@xxxxxxxxx>
Date: Fri, 21 Oct 2016 22:08:39 +0200
On 21-10-16 19:47, Guy Harris wrote:
> On Oct 21, 2016, at 9:57 AM, Thomas Wiens <th.wiens@xxxxxx> 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.

For my understanding, would this be covered by using
val_to_str_wmem(wmem_file_scope(), val, vs, fmt);

Thanks,
Jaap