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

[or-cvs] backport: make the numbers in read-history and write-histor...



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

Modified Files:
      Tag: tor-0_1_0-patches
	rephist.c 
Log Message:
backport: make the numbers in read-history and write-history into uint64s,
so they don't overflow and publish negatives in the descriptor.
fixes bug 193.


Index: rephist.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/rephist.c,v
retrieving revision 1.56
retrieving revision 1.56.2.1
diff -u -d -r1.56 -r1.56.2.1
--- rephist.c	1 Apr 2005 20:15:55 -0000	1.56
+++ rephist.c	23 Sep 2005 08:32:54 -0000	1.56.2.1
@@ -412,7 +412,7 @@
   int total_obs; /**< Total for all members of obs except obs[cur_obs_idx] */
   int max_total; /**< Largest value that total_obs has taken on in the current
                   * period. */
-  int total_in_period; /**< Total bytes transferred in the current period. */
+  uint64_t total_in_period; /**< Total bytes transferred in the current period. */
 
   /** When does the next period begin? */
   time_t next_period;
@@ -427,7 +427,7 @@
   int maxima[NUM_TOTALS];
   /** Circular array of the total bandwidth usage for the last NUM_TOTALS
    * periods */
-  int totals[NUM_TOTALS];
+  uint64_t totals[NUM_TOTALS];
 } bw_array_t;
 
 /** Shift the current period of b forward by one.
@@ -587,7 +587,7 @@
   size_t len;
 
   /* opt (read|write)-history yyyy-mm-dd HH:MM:SS (n s) n,n,n,n,n... */
-  len = (60+12*NUM_TOTALS)*2;
+  len = (60+20*NUM_TOTALS)*2;
   buf = tor_malloc_zero(len);
   cp = buf;
   for (r=0;r<2;++r) {
@@ -609,9 +609,11 @@
     for (n=0; n<b->num_maxes_set; ++n,++i) {
       while (i >= NUM_TOTALS) i -= NUM_TOTALS;
       if (n==(b->num_maxes_set-1))
-        tor_snprintf(cp, len-(cp-buf), "%d", b->totals[i]);
+        tor_snprintf(cp, len-(cp-buf), U64_FORMAT,
+                     U64_PRINTF_ARG(b->totals[i]));
       else
-        tor_snprintf(cp, len-(cp-buf), "%d,", b->totals[i]);
+        tor_snprintf(cp, len-(cp-buf), U64_FORMAT",",
+                     U64_PRINTF_ARG(b->totals[i]));
       cp += strlen(cp);
     }
     strlcat(cp, "\n", len-(cp-buf));