Browse Source

Thats the letter I and the number 2. (Apologies to Negativland)

svn:r279
Nick Mathewson 22 years ago
parent
commit
39314a13b0
2 changed files with 5 additions and 3 deletions
  1. 3 3
      src/or/main.c
  2. 2 0
      src/or/test.c

+ 3 - 3
src/or/main.c

@@ -696,11 +696,12 @@ int
 dump_signed_directory_to_string_impl(char *s, int maxlen, directory_t *dir,
                                      crypto_pk_env_t *private_key)
 {
-  char *cp;
+  char *cp, *eos;
   char digest[20];
   char signature[128];
   int i, written;
   routerinfo_t *router;
+  eos = s+maxlen;
   strncpy(s, 
           "signed-directory\n"
           "client-software x y z\n" /* XXX make this real */
@@ -711,14 +712,13 @@ dump_signed_directory_to_string_impl(char *s, int maxlen, directory_t *dir,
   cp = s+i;
   for (i = 0; i < dir->n_routers; ++i) {
     router = dir->routers[i];
-    written = dump_router_to_string(cp, maxlen-i, router);
+    written = dump_router_to_string(cp, eos-cp, router);
 
     if(written < 0) { 
       log(LOG_ERR,"dump_signed_directory_to_string(): tried to exceed string length.");
       cp[maxlen-1] = 0; /* make sure it's null terminated */
       return -1;
     }
-    i += written;
     cp += written;
   }
 

+ 2 - 0
src/or/test.c

@@ -634,6 +634,8 @@ test_dir_format()
   /* puts(buf); */
   
   test_assert(! router_get_dir_from_string_impl(buf, &dir2, pk1));
+  test_eq(2, dir2->n_routers);
+  
 
   if (pk1_str) free(pk1_str);
   if (pk2_str) free(pk2_str);