aboutsummaryrefslogtreecommitdiffstats
path: root/epan/proto.h
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2018-09-20 00:29:35 +0200
committerGerald Combs <gerald@wireshark.org>2018-09-20 20:59:57 +0000
commitf3296cdbb66bef47c553e000df8e60ad45b68a5a (patch)
treeca2816aafbf5eaf61a27dcad5cfaae645a2eb89d /epan/proto.h
parente3423b134fda3e32717f867e8c50589f57786f20 (diff)
proto.h: add type checks for VALS/VALS64/VALS_EXT_PTR/TFS/RVALS
These macros were evil as they silently ignored bad casts. Together with an updated checkAPIs.pl, this should reduce the likelihood of errors. Change-Id: I40ecc48a57b2061b4c65db4f4f7fffff21f159a8 Reviewed-on: https://code.wireshark.org/review/29757 Petri-Dish: Peter Wu <peter@lekensteyn.nl> Tested-by: Petri Dish Buildbot Reviewed-by: Gerald Combs <gerald@wireshark.org>
Diffstat (limited to 'epan/proto.h')
-rw-r--r--epan/proto.h13
1 files changed, 8 insertions, 5 deletions
diff --git a/epan/proto.h b/epan/proto.h
index e10e6c81e7..c6bec70941 100644
--- a/epan/proto.h
+++ b/epan/proto.h
@@ -66,17 +66,20 @@ WS_DLL_PUBLIC int hf_text_only;
struct expert_field;
+/* Type-check that 'x' is compatible with 'type', should give compiler warnings otherwise. */
+#define cast_same(type, x) (0 ? (type)0 : (x))
+
/** Make a const value_string[] look like a _value_string pointer, used to set header_field_info.strings */
-#define VALS(x) (const struct _value_string*)(x)
+#define VALS(x) (cast_same(const struct _value_string*, (x)))
/** Make a const val64_string[] look like a _val64_string pointer, used to set header_field_info.strings */
-#define VALS64(x) (const struct _val64_string*)(x)
+#define VALS64(x) (cast_same(const struct _val64_string*, (x)))
/** Something to satisfy checkAPIs when you have a pointer to a value_string_ext (e.g., one built with value_string_ext_new()) */
-#define VALS_EXT_PTR(x) (x)
+#define VALS_EXT_PTR(x) (cast_same(value_string_ext*, (x)))
/** Make a const true_false_string[] look like a _true_false_string pointer, used to set header_field_info.strings */
-#define TFS(x) (const struct true_false_string*)(x)
+#define TFS(x) (cast_same(const struct true_false_string*, (x)))
typedef void (*custom_fmt_func_t)(gchar *, guint32);
@@ -93,7 +96,7 @@ typedef void (*custom_fmt_func_64_t)(gchar *, guint64);
/** Make a const range_string[] look like a _range_string pointer, used to set
* header_field_info.strings */
-#define RVALS(x) (const struct _range_string*)(x)
+#define RVALS(x) (cast_same(const struct _range_string*, (x)))
/** Cast a ft_framenum_type_t, used to set header_field_info.strings */
#define FRAMENUM_TYPE(x) GINT_TO_POINTER(x)