From 49466f95bc1fe3cc139f3750fcc934ffc210faef Mon Sep 17 00:00:00 2001 From: Jeff Morriss Date: Sun, 2 Dec 2012 04:49:13 +0000 Subject: Introduce, and start using, TVB_SET_ADDRESS() and TVB_SET_ADDRESS_HF(). They are like the non-TVB versions except that they take a TVB and an offset instead of (frequently) a pointer into the TVB. Calling tvb_get_ptr() before modifying the rest of the fields should help fix https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=7960 (though I can't reproduce that problem). Replace a bunch of calls like: SET_ADDRESS(..., AT_XXX, length, tvb_get_ptr(tvb, offset, length)); with: TVB_SET_ADDRESS(..., AT_XXX, tvb, offset, length); svn path=/trunk/; revision=46324 --- epan/address.h | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'epan/address.h') diff --git a/epan/address.h b/epan/address.h index e650699647..cf20d3c48c 100644 --- a/epan/address.h +++ b/epan/address.h @@ -70,17 +70,45 @@ typedef struct _address { } address; #define SET_ADDRESS(addr, addr_type, addr_len, addr_data) { \ + (addr)->data = (addr_data); \ + (addr)->type = (addr_type); \ + (addr)->hf = -1; \ + (addr)->len = (addr_len); \ + } + +/* Same as SET_ADDRESS but it takes a TVB and an offset instead of + * (frequently) a pointer into a TVB. This allow us to get the tvb_get_ptr() + * call out of the dissectors. + * + * Call tvb_get_ptr() first in case it throws an exception: then we won't + * modify the address at all. + */ +#define TVB_SET_ADDRESS(addr, addr_type, tvb, offset, addr_len) { \ + (addr)->data = tvb_get_ptr(tvb, offset, addr_len); \ (addr)->type = (addr_type); \ (addr)->hf = -1; \ (addr)->len = (addr_len); \ - (addr)->data = (addr_data); \ } #define SET_ADDRESS_HF(addr, addr_type, addr_len, addr_data, addr_hf) { \ + (addr)->data = (addr_data); \ + (addr)->type = (addr_type); \ + (addr)->hf = (addr_hf); \ + (addr)->len = (addr_len); \ + } + +/* Same as SET_ADDRESS_HF but it takes a TVB and an offset instead of + * (frequently) a pointer into a TVB. This allow us to get the tvb_get_ptr() + * call out of the dissectors. + * + * Call tvb_get_ptr() first in case it throws an exception: then we won't + * modify the address at all. + */ +#define TVB_SET_ADDRESS_HF(addr, addr_type, tvb, offset, addr_len, addr_hf) { \ + (addr)->data = tvb_get_ptr(tvb, offset, addr_len); \ (addr)->type = (addr_type); \ (addr)->hf = (addr_hf); \ (addr)->len = (addr_len); \ - (addr)->data = (addr_data); \ } /* -- cgit v1.2.3