[tor-commits] [tor/master] Tweak policies_log_first_redundant_entry even more

nickm at torproject.org nickm at torproject.org
Wed Dec 9 16:31:31 UTC 2015


commit 580d788b3f85ee04f8893325b902bf28727a451b
Author: Nick Mathewson <nickm at torproject.org>
Date:   Wed Dec 9 11:04:56 2015 -0500

    Tweak policies_log_first_redundant_entry even more
    
      * Use smartlist_foreach_begin/end instead of a plain for loop.
      * constify the pointers.
---
 src/or/policies.c |   13 ++++++-------
 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 ec29b23..07f8cd7 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 bb56bf4..007f494 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);





More information about the tor-commits mailing list