[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] Dr. Seuss on iterating circular lists: "It"s fun to have fu...



Update of /home/or/cvsroot/tor/src/or
In directory moria.mit.edu:/tmp/cvs-serv6038/src/or

Modified Files:
	circuitbuild.c 
Log Message:
Dr. Seuss on iterating circular lists: "It's fun to have fun, but you
have to know how."


Index: circuitbuild.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/circuitbuild.c,v
retrieving revision 1.60
retrieving revision 1.61
diff -u -d -r1.60 -r1.61
--- circuitbuild.c	23 Nov 2004 00:11:36 -0000	1.60
+++ circuitbuild.c	23 Nov 2004 06:08:08 -0000	1.61
@@ -86,9 +86,12 @@
     smartlist_add(elements, tor_strdup(buf));
   }
 
-  for (hop = circ->cpath; hop && hop != circ->cpath; hop = hop->next) {
+  hop = circ->cpath;
+  do {
     const char *elt;
     routerinfo_t *r;
+    if (!hop)
+      break;
     if (!verbose && hop->state != CPATH_STATE_OPEN)
       break;
     if ((r = router_get_by_digest(hop->identity_digest))) {
@@ -109,7 +112,8 @@
     } else {
       smartlist_add(elements, tor_strdup(elt));
     }
-  }
+    hop = hop->next;
+  } while (hop != circ->cpath);
 
   s = smartlist_join_strings(elements, verbose?" ":",", 0, NULL);
   SMARTLIST_FOREACH(elements, char*, cp, tor_free(cp));
@@ -212,10 +216,14 @@
     if(circ->state == CIRCUIT_STATE_BUILDING)
       log(severity,"Building: desired len %d, planned exit node %s.",
           circ->build_state->desired_path_len, circ->build_state->chosen_exit_name);
-    for(hop=circ->cpath;hop->next != circ->cpath; hop=hop->next)
+    hop = circ->cpath;
+    do {
+      if (!hop) break;
       log(severity,"hop: state %d, addr 0x%.8x, port %d", hop->state,
           (unsigned int)hop->addr,
           (int)hop->port);
+      hop = hop->next;
+    } while (hop != circ->cpath);
   }
 }