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

[tor-commits] [tor/master] Use u32 add helper for CIRC_BW accounting.



commit f921fd771ae51a82d971be064edca86b11f6004b
Author: Mike Perry <mikeperry-git@xxxxxxxxxxxxxx>
Date:   Mon Apr 2 07:16:19 2018 +0000

    Use u32 add helper for CIRC_BW accounting.
    
    There are quite a few other places this could be used, but keeping it simple
    for now.
---
 src/or/command.c | 7 ++-----
 src/or/relay.c   | 7 ++-----
 2 files changed, 4 insertions(+), 10 deletions(-)

diff --git a/src/or/command.c b/src/or/command.c
index 18cbbca25..4fa05a18b 100644
--- a/src/or/command.c
+++ b/src/or/command.c
@@ -504,11 +504,8 @@ command_process_relay_cell(cell_t *cell, channel_t *chan)
     origin_circuit_t *ocirc = TO_ORIGIN_CIRCUIT(circ);
 
     /* Count the payload bytes only. We don't care about cell headers */
-    if (PREDICT_LIKELY(UINT32_MAX - ocirc->n_read_circ_bw >
-                CELL_PAYLOAD_SIZE))
-      ocirc->n_read_circ_bw += (int)CELL_PAYLOAD_SIZE;
-    else
-      ocirc->n_read_circ_bw = UINT32_MAX;
+    ocirc->n_read_circ_bw = tor_add_u32_nowrap(ocirc->n_read_circ_bw,
+                                               CELL_PAYLOAD_SIZE);
   }
 
   if (!CIRCUIT_IS_ORIGIN(circ) &&
diff --git a/src/or/relay.c b/src/or/relay.c
index d43720478..472e73b75 100644
--- a/src/or/relay.c
+++ b/src/or/relay.c
@@ -374,11 +374,8 @@ circuit_package_relay_cell(cell_t *cell, circuit_t *circ,
 
     /* Update circ written totals for control port */
     origin_circuit_t *ocirc = TO_ORIGIN_CIRCUIT(circ);
-    if (PREDICT_LIKELY(UINT32_MAX - ocirc->n_written_circ_bw
-          > CELL_PAYLOAD_SIZE))
-      ocirc->n_written_circ_bw += (int)CELL_PAYLOAD_SIZE;
-    else
-      ocirc->n_written_circ_bw = UINT32_MAX;
+    ocirc->n_written_circ_bw = tor_add_u32_nowrap(ocirc->n_written_circ_bw,
+                                                  CELL_PAYLOAD_SIZE);
 
   } else { /* incoming cell */
     if (CIRCUIT_IS_ORIGIN(circ)) {



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits