aboutsummaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorDavid Goulet <dgoulet@torproject.org>2018-04-16 15:02:51 -0400
committerDavid Goulet <dgoulet@torproject.org>2018-04-16 15:05:41 -0400
commitae4e5b98245169dc02c12138d4acc69ce7da0261 (patch)
treed328ae19cd0a6eac405847cafec6bd66b411ce72 /src/common
parentc7d3de216c60c090fddb4926a739da038bb5d5fe (diff)
downloadtor-ae4e5b98245169dc02c12138d4acc69ce7da0261.tar.gz
tor-ae4e5b98245169dc02c12138d4acc69ce7da0261.zip
token: Fix uint32_t to uint64_t conversion
Unfortunately, the units passed to monotime_coarse_stamp_units_to_approx_msec() was always 0 due to a type conversion. Signed-off-by: David Goulet <dgoulet@torproject.org>
Diffstat (limited to 'src/common')
-rw-r--r--src/common/token_bucket.c5
-rw-r--r--src/common/token_bucket.h3
2 files changed, 6 insertions, 2 deletions
diff --git a/src/common/token_bucket.c b/src/common/token_bucket.c
index 5d97a920fb..d18731b0e3 100644
--- a/src/common/token_bucket.c
+++ b/src/common/token_bucket.c
@@ -108,7 +108,7 @@ token_bucket_raw_dec(token_bucket_raw_t *bucket,
}
/** Convert a rate in bytes per second to a rate in bytes per step */
-static uint32_t
+STATIC uint32_t
rate_per_sec_to_rate_per_step(uint32_t rate)
{
/*
@@ -117,8 +117,9 @@ rate_per_sec_to_rate_per_step(uint32_t rate)
(rate / 1000) * to_approximate_msec(TICKS_PER_STEP). But to minimize
rounding error, we do it this way instead, and divide last.
*/
+ uint64_t units = (uint64_t) rate * TICKS_PER_STEP;
uint32_t val = (uint32_t)
- monotime_coarse_stamp_units_to_approx_msec(rate*TICKS_PER_STEP)/1000;
+ monotime_coarse_stamp_units_to_approx_msec(units) / 1000;
return val ? val : 1;
}
diff --git a/src/common/token_bucket.h b/src/common/token_bucket.h
index 329b652f8e..fb5d9fc60a 100644
--- a/src/common/token_bucket.h
+++ b/src/common/token_bucket.h
@@ -10,6 +10,7 @@
#define TOR_TOKEN_BUCKET_H
#include "torint.h"
+#include "testsupport.h"
/** Largest allowable burst value for a token buffer. */
#define TOKEN_BUCKET_MAX_BURST INT32_MAX
@@ -109,6 +110,8 @@ token_bucket_rw_get_write(const token_bucket_rw_t *bucket)
* a power of two if you can. */
#define TICKS_PER_STEP 16
+STATIC uint32_t rate_per_sec_to_rate_per_step(uint32_t rate);
+
#endif
#endif /* TOR_TOKEN_BUCKET_H */