summaryrefslogtreecommitdiff
path: root/src/or/statefile.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2017-09-25 11:08:11 -0400
committerNick Mathewson <nickm@torproject.org>2017-09-26 12:24:04 -0400
commiteb54a856a298aff8b2cdadf87247a33a74921c49 (patch)
treecfd297e78927fe247341d3eafdb6c71e97b59058 /src/or/statefile.c
parent90e8d1f58fb77eb15c59c1bd846aabe1555b64f2 (diff)
downloadtor-eb54a856a298aff8b2cdadf87247a33a74921c49.tar.gz
tor-eb54a856a298aff8b2cdadf87247a33a74921c49.zip
Add test to make sure all confparse variables are well-typed
New approach, suggested by Taylor: During testing builds, we initialize a union member of an appropriate pointer type with the address of the member field we're trying to test, so we can make sure that the compiler doesn't warn. My earlier approach invoked undefined behavior.
Diffstat (limited to 'src/or/statefile.c')
-rw-r--r--src/or/statefile.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/or/statefile.c b/src/or/statefile.c
index 9ee80f2e3c..97bd9cac36 100644
--- a/src/or/statefile.c
+++ b/src/or/statefile.c
@@ -54,10 +54,14 @@ static config_abbrev_t state_abbrevs_[] = {
{ NULL, NULL, 0, 0},
};
+/** dummy instance of or_state_t, used for type-checking its
+ * members with CONF_CHECK_VAR_TYPE. */
+DUMMY_TYPECHECK_INSTANCE(or_state_t);
+
/*XXXX these next two are duplicates or near-duplicates from config.c */
#define VAR(name,conftype,member,initvalue) \
{ name, CONFIG_TYPE_ ## conftype, offsetof(or_state_t, member), \
- initvalue }
+ initvalue CONF_TEST_MEMBERS(or_state_t, conftype, member) }
/** As VAR, but the option name and member name are the same. */
#define V(member,conftype,initvalue) \
VAR(#member, conftype, member, initvalue)
@@ -116,7 +120,8 @@ static config_var_t state_vars_[] = {
V(CircuitBuildAbandonedCount, UINT, "0"),
VAR("CircuitBuildTimeBin", LINELIST_S, BuildtimeHistogram, NULL),
VAR("BuildtimeHistogram", LINELIST_V, BuildtimeHistogram, NULL),
- { NULL, CONFIG_TYPE_OBSOLETE, 0, NULL }
+
+ END_OF_CONFIG_VARS
};
#undef VAR
@@ -135,6 +140,7 @@ static int or_state_validate_cb(void *old_options, void *options,
* lets us preserve options from versions of Tor newer than us. */
static config_var_t state_extra_var = {
"__extra", CONFIG_TYPE_LINELIST, offsetof(or_state_t, ExtraLines), NULL
+ CONF_TEST_MEMBERS(or_state_t, LINELIST, ExtraLines)
};
/** Configuration format for or_state_t. */