This is a static archive of our old Q&A Site. Please post any new questions and answers at ask.wireshark.org.

val_to_str function return

0

val_to_str(int1,data,"%s");

when using this function it works fine but if int1 isn't found in the value_string structure then it crashes wireshark. The value_string structure looks like this:

static const value_string data[] = { { 0x01, "Test1" }, { 0x03, "Test2" }, { 0, NULL } };

so if the value 0x02 was used then wireshark would crash. I thought it would return NULL if the value wasnt found. Is there any return value I can check to make sure its returning a valid string?

asked 13 Feb '13, 14:19

StealthUE's gravatar image

StealthUE
667713
accept rate: 100%


One Answer:

1

val_to_str will pass int1 to the format string if it isn't found in data. If you use "%s" as your format string and pass in the value 2 then val_to_str will go looking for a valid string at memory address 2. You might try using "%d" or "%u" instead.

answered 13 Feb '13, 14:50

Gerald%20Combs's gravatar image

Gerald Combs ♦♦
3.3k92258
accept rate: 24%

thanks..."%d" worked

(13 Feb '13, 15:09) StealthUE