diff options
author | Nick Mathewson <nickm@torproject.org> | 2015-12-09 11:04:56 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2015-12-09 11:04:57 -0500 |
commit | 580d788b3f85ee04f8893325b902bf28727a451b (patch) | |
tree | 543076a6e8ca31fe29809efeae547e7701e7599c /src | |
parent | db433b8dc3c8684e6a86365e12336a708f67edaa (diff) | |
download | tor-580d788b3f85ee04f8893325b902bf28727a451b.tar.gz tor-580d788b3f85ee04f8893325b902bf28727a451b.zip |
Tweak policies_log_first_redundant_entry even more
* Use smartlist_foreach_begin/end instead of a plain for loop.
* constify the pointers.
Diffstat (limited to 'src')
-rw-r--r-- | src/or/policies.c | 13 | ||||
-rw-r--r-- | src/or/policies.h | 2 |
2 files changed, 7 insertions, 8 deletions
diff --git a/src/or/policies.c b/src/or/policies.c index ec29b23c3e..07f8cd7c40 100644 --- a/src/or/policies.c +++ b/src/or/policies.c @@ -1129,12 +1129,10 @@ policies_log_first_redundant_entry(const smartlist_t *policy) int found_final_effective_entry = 0; int first_redundant_entry = 0; tor_assert(policy); - for (int i = 0; i < smartlist_len(policy); ++i) { + SMARTLIST_FOREACH_BEGIN(policy, const addr_policy_t *, p) { sa_family_t family; - addr_policy_t *p; int found_ipv4_wildcard = 0, found_ipv6_wildcard = 0; - - p = smartlist_get(policy, i); + const int i = p_sl_idx; /* Look for accept/reject *[4|6|]:* entires */ if (p->prt_min <= 1 && p->prt_max == 65535 && p->maskbits == 0) { @@ -1162,10 +1160,11 @@ policies_log_first_redundant_entry(const smartlist_t *policy) } break; } - } + } SMARTLIST_FOREACH_END(p); + /* Work out if there are redundant trailing entries in the policy list */ if (found_final_effective_entry && first_redundant_entry > 0) { - addr_policy_t *p; + const addr_policy_t *p; /* Longest possible policy is * "accept6 ffff:ffff:..255/128:10000-65535", * which contains a max-length IPv6 address, plus 24 characters. */ @@ -1504,7 +1503,7 @@ policy_is_reject_star(const smartlist_t *policy, sa_family_t family) /** Write a single address policy to the buf_len byte buffer at buf. Return * the number of characters written, or -1 on failure. */ int -policy_write_item(char *buf, size_t buflen, addr_policy_t *policy, +policy_write_item(char *buf, size_t buflen, const addr_policy_t *policy, int format_for_desc) { size_t written = 0; diff --git a/src/or/policies.h b/src/or/policies.h index bb56bf42b8..007f494482 100644 --- a/src/or/policies.h +++ b/src/or/policies.h @@ -75,7 +75,7 @@ char * policy_dump_to_string(const smartlist_t *policy_list, int getinfo_helper_policies(control_connection_t *conn, const char *question, char **answer, const char **errmsg); -int policy_write_item(char *buf, size_t buflen, addr_policy_t *item, +int policy_write_item(char *buf, size_t buflen, const addr_policy_t *item, int format_for_desc); void addr_policy_list_free(smartlist_t *p); |