diff options
author | David Goulet <dgoulet@torproject.org> | 2018-04-16 15:02:51 -0400 |
---|---|---|
committer | David Goulet <dgoulet@torproject.org> | 2018-04-16 15:05:41 -0400 |
commit | ae4e5b98245169dc02c12138d4acc69ce7da0261 (patch) | |
tree | d328ae19cd0a6eac405847cafec6bd66b411ce72 /src/common/token_bucket.c | |
parent | c7d3de216c60c090fddb4926a739da038bb5d5fe (diff) | |
download | tor-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/token_bucket.c')
-rw-r--r-- | src/common/token_bucket.c | 5 |
1 files changed, 3 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; } |