]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
r11909@catbus: nickm | 2007-02-24 02:37:40 -0500
authorNick Mathewson <nickm@torproject.org>
Sat, 24 Feb 2007 07:37:45 +0000 (07:37 +0000)
committerNick Mathewson <nickm@torproject.org>
Sat, 24 Feb 2007 07:37:45 +0000 (07:37 +0000)
 Move tricky "delete the member of the smartlist currently under iteration" logic into its own happyfun macro.

svn:r9633

src/common/container.h
src/or/circuitbuild.c

index ff2d3cb011d4f6d4d7a85003318c8735c479e612..fbd3c6c603987d03e74cd7be5c6893179b5d4d6c 100644 (file)
@@ -156,6 +156,16 @@ char *smartlist_join_strings2(smartlist_t *sl, const char *join,
       cmd;                                                      \
     } } while (0)
 
+/** Helper: While in a SMARTLIST_FOREACH loop over the list <b>sl</b> indexed
+ * with the variable <b>var</b>, remover the current element in a way that
+ * won't confuse the loop. */
+#define SMARTLIST_DEL_CURRENT(sl, var)          \
+  do {                                          \
+    smartlist_del(sl, var ## _sl_idx);          \
+    --var ## _sl_idx;                           \
+    --var ## _sl_len;                           \
+  } while (0);
+
 #define DECLARE_MAP_FNS(maptype, keytype, prefix)                       \
   typedef struct maptype maptype;                                       \
   typedef struct prefix##entry_t *prefix##iter_t;                       \
index 58e85da590d565693e342a4dd28fca4f9a00d908..fa6cd5108dbd70a38ce055163c5e35e51003bdaf 100644 (file)
@@ -2280,8 +2280,7 @@ entry_guards_prepend_from_config(void)
   /* Remove all currently configured entry guards from entry_routers. */
   SMARTLIST_FOREACH(entry_routers, routerinfo_t *, ri, {
     if (is_an_entry_guard(ri->cache_info.identity_digest)) {
-      smartlist_del(entry_routers, ri_sl_idx--);
-      ri_sl_len--;
+      SMARTLIST_DEL_CURRENT(entry_routers, ri);
     }
   });