[or-cvs] backport the fix to smartlist_join_strings2()

arma at seul.org arma at seul.org
Tue Jul 19 21:33:14 UTC 2005


Update of /home/or/cvsroot/tor/src/common
In directory moria:/home/arma/work/onion/tor-010x/tor/src/common

Modified Files:
      Tag: tor-0_1_0-patches
	container.c 
Log Message:
backport the fix to smartlist_join_strings2()


Index: container.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/common/container.c,v
retrieving revision 1.25
retrieving revision 1.25.2.1
diff -u -d -r1.25 -r1.25.2.1
--- container.c	3 Apr 2005 06:00:00 -0000	1.25
+++ container.c	19 Jul 2005 21:33:12 -0000	1.25.2.1
@@ -354,20 +354,28 @@
 
   tor_assert(sl);
   tor_assert(join);
+
+  if (terminate)
+    n = join_len;
+
   for (i = 0; i < sl->num_used; ++i) {
     n += strlen(sl->list[i]);
-    n += join_len;
+    if (i+1 < sl->num_used) /* avoid double-counting the last one */
+      n += join_len;
   }
-  if (!terminate) n -= join_len;
   dst = r = tor_malloc(n+1);
   for (i = 0; i < sl->num_used; ) {
     for (src = sl->list[i]; *src; )
       *dst++ = *src++;
-    if (++i < sl->num_used || terminate) {
+    if (++i < sl->num_used) {
       memcpy(dst, join, join_len);
       dst += join_len;
     }
   }
+  if (terminate) {
+    memcpy(dst, join, join_len);
+    dst += join_len;
+  }
   *dst = '\0';
 
   if (len_out)



More information about the tor-commits mailing list