diff options
author | Nick Mathewson <nickm@torproject.org> | 2019-11-11 12:20:14 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2019-11-11 12:20:14 -0500 |
commit | 7c3378fb8d37e1f22ae7f04012e3e57a16b7f2fc (patch) | |
tree | a0cd68ca420872d26dc689d49ae1fbd6d71fc8ee /src/test | |
parent | 01af3a55f41de991c0b59d5bf12c100c82829b47 (diff) | |
parent | 42ba3997d64591822411fbbedd51a240dbbb5fab (diff) | |
download | tor-7c3378fb8d37e1f22ae7f04012e3e57a16b7f2fc.tar.gz tor-7c3378fb8d37e1f22ae7f04012e3e57a16b7f2fc.zip |
Merge remote-tracking branch 'tor-github/pr/1338'
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/test_confparse.c | 17 | ||||
-rw-r--r-- | src/test/test_util.c | 9 |
2 files changed, 23 insertions, 3 deletions
diff --git a/src/test/test_confparse.c b/src/test/test_confparse.c index 3e122a5129..808389de14 100644 --- a/src/test/test_confparse.c +++ b/src/test/test_confparse.c @@ -898,11 +898,22 @@ test_confparse_unitparse(void *args) tt_assert(ok); /* u64 overflow */ - /* XXXX our implementation does not currently detect this. See bug 30920. */ - /* tt_u64_op(config_parse_memunit("20000000 TB", &ok), OP_EQ, 0); tt_assert(!ok); - */ + // This test fails the double check as the float representing 15000000.5 TB + // is greater than (double) INT64_MAX + tt_u64_op(config_parse_memunit("15000000.5 TB", &ok), OP_EQ, 0); + tt_assert(!ok); + // 8388608.1 TB passes double check because it falls in the same float + // value as (double)INT64_MAX (which is 2^63) due to precision. + // But will fail the int check because the unsigned representation of + // the float, which is 2^63, is strictly greater than INT64_MAX (2^63-1) + tt_u64_op(config_parse_memunit("8388608.1 TB", &ok), OP_EQ, 0); + tt_assert(!ok); + + /* negative float */ + tt_u64_op(config_parse_memunit("-1.5 GB", &ok), OP_EQ, 0); + tt_assert(!ok); /* i32 overflow */ tt_int_op(config_parse_interval("1000 months", &ok), OP_EQ, -1); diff --git a/src/test/test_util.c b/src/test/test_util.c index 3e4975fcd8..5f46e4fcff 100644 --- a/src/test/test_util.c +++ b/src/test/test_util.c @@ -33,6 +33,7 @@ #include "lib/process/env.h" #include "lib/process/pidfile.h" #include "lib/intmath/weakrng.h" +#include "lib/intmath/muldiv.h" #include "lib/thread/numcpus.h" #include "lib/math/fp.h" #include "lib/math/laplace.h" @@ -5975,6 +5976,14 @@ test_util_nowrap_math(void *arg) tt_u64_op(UINT32_MAX, OP_EQ, tor_add_u32_nowrap(2, UINT32_MAX-1)); tt_u64_op(UINT32_MAX, OP_EQ, tor_add_u32_nowrap(UINT32_MAX, UINT32_MAX)); + tt_u64_op(0, OP_EQ, tor_mul_u64_nowrap(0, 0)); + tt_u64_op(1, OP_EQ, tor_mul_u64_nowrap(1, 1)); + tt_u64_op(2, OP_EQ, tor_mul_u64_nowrap(2, 1)); + tt_u64_op(4, OP_EQ, tor_mul_u64_nowrap(2, 2)); + tt_u64_op(UINT64_MAX, OP_EQ, tor_mul_u64_nowrap(UINT64_MAX, 1)); + tt_u64_op(UINT64_MAX, OP_EQ, tor_mul_u64_nowrap(2, UINT64_MAX)); + tt_u64_op(UINT64_MAX, OP_EQ, tor_mul_u64_nowrap(UINT64_MAX, UINT64_MAX)); + done: ; } |