diff --git a/.travis.yml b/.travis.yml index 5c405bc0e..3e8e98b85 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,7 @@ language: cpp matrix: include: - env: variant=test_release coverage=1 toolset=gcc-coverage - - env: variant=test_debug sim=1 ssl=openssl crypto=libcrypto toolset=gcc + - env: variant=test_debug sim=1 ssl=openssl crypto=libcrypto toolset=ubsan - env: variant=test_barebones toolset=gcc - env: autotools=1 toolset=gcc - os: osx @@ -64,7 +64,10 @@ before_install: - if [ "$coverage" == "1" ]; then pip install --user codecov; fi - - 'echo "using toolset: " ${toolset}' + - 'if [[ $lang == "ubsan" ]]; then export test_args=testing.arg="--no-stderr-redirect"; fi' + - 'echo "toolset: " ${toolset}' + - 'echo "coverage_toolset: " ${coverage_toolset}' + - 'echo "variant: " ${variant}' install: @@ -73,13 +76,16 @@ install: g++-5 --version; echo "using gcc : : ccache g++-5 : -std=c++11 ;" >> ~/user-config.jam; fi' + - 'if [[ $toolset == "gcc-ubsan" ]]; then + echo "using gcc : ubsan : ccache g++-5 : -std=c++11 -fsanitize=undefined -fno-sanitize-recover=undefined -fsanitize=undefined -fno-sanitize-recover=undefined ;" >> ~/user-config.jam; + fi' - 'if [[ $toolset == "gcc-coverage" ]]; then echo "using gcc : coverage : ccache g++-5 --coverage : -std=c++11 --coverage ;" >> ~/user-config.jam; fi' - 'if [[ $toolset == "gcc-arm" ]]; then echo "using gcc : arm : ccache armv8l-linux-gnueabihf-g++ : \"-std=c++11 -fsigned-char -march=armv8-a+crc -mfpu=crypto-neon-fp-armv8 -DTORRENT_FORCE_ARM_CRC32\" -lm ;" >> ~/user-config.jam; fi;' - - 'echo "using darwin : : ccache clang++ : -std=c11 -std=c++11 ;" >> ~/user-config.jam' + - 'echo "using darwin : : ccache clang++ : -std=c++11 ;" >> ~/user-config.jam' - 'echo "using python : 2.7 ;" >> ~/user-config.jam' - if [ "$docs" == "1" ]; then rst2html.py --version; fi @@ -145,7 +151,7 @@ script: fi' - cd bindings/python - - 'if [ "$variant" != "" ]; then + - 'if [[ "$lang" != "ubsan" && "$variant" != "" ]]; then bjam -j3 warnings-as-errors=on ssl=$ssl crypto=$crypto debug-iterators=on picker-debugging=on invariant-checks=full $toolset variant=$variant stage_module libtorrent-link=shared install-type=LIB dll-path=../../lib && LD_LIBRARY_PATH=../../lib DYLD_LIBRARY_PATH=../../lib python test.py; fi' diff --git a/Jamfile b/Jamfile index 04c7da969..ca030c9eb 100644 --- a/Jamfile +++ b/Jamfile @@ -288,7 +288,6 @@ rule warnings ( properties * ) { # disable warning C4503: decorated name length exceeded, name was truncated result += /wd4503 ; - result += all ; # enable these warnings again, once the other ones are dealt with @@ -521,7 +520,7 @@ variant test_release : release : production on full shared off on on multi - off + on ; variant test_debug : debug : on on diff --git a/bindings/python/src/torrent_handle.cpp b/bindings/python/src/torrent_handle.cpp index 3818acc97..f756740a0 100644 --- a/bindings/python/src/torrent_handle.cpp +++ b/bindings/python/src/torrent_handle.cpp @@ -434,7 +434,7 @@ void bind_torrent_handle() #ifndef TORRENT_DISABLE_DHT .def("force_dht_announce", _(&torrent_handle::force_dht_announce)) #endif - .def("scrape_tracker", _(&torrent_handle::scrape_tracker)) + .def("scrape_tracker", _(&torrent_handle::scrape_tracker), arg("index") = -1) .def("set_upload_mode", _(&torrent_handle::set_upload_mode)) .def("set_share_mode", _(&torrent_handle::set_share_mode)) .def("flush_cache", &torrent_handle::flush_cache) diff --git a/ed25519/src/fe.cpp b/ed25519/src/fe.cpp index 809f0c335..d8b1a7e2d 100644 --- a/ed25519/src/fe.cpp +++ b/ed25519/src/fe.cpp @@ -34,6 +34,9 @@ static u64 load_4(const unsigned char *in) { return result; } +static inline i64 shift_left(i64 v, int s) { + return i64(u64(v) << s); +} /* @@ -326,34 +329,34 @@ void fe_frombytes(fe h, const unsigned char *s) { carry9 = (h9 + (i64) (1 << 24)) >> 25; h0 += carry9 * 19; - h9 -= carry9 << 25; + h9 -= shift_left(carry9, 25); carry1 = (h1 + (i64) (1 << 24)) >> 25; h2 += carry1; - h1 -= carry1 << 25; + h1 -= shift_left(carry1, 25); carry3 = (h3 + (i64) (1 << 24)) >> 25; h4 += carry3; - h3 -= carry3 << 25; + h3 -= shift_left(carry3, 25); carry5 = (h5 + (i64) (1 << 24)) >> 25; h6 += carry5; - h5 -= carry5 << 25; + h5 -= shift_left(carry5, 25); carry7 = (h7 + (i64) (1 << 24)) >> 25; h8 += carry7; - h7 -= carry7 << 25; + h7 -= shift_left(carry7, 25); carry0 = (h0 + (i64) (1 << 25)) >> 26; h1 += carry0; - h0 -= carry0 << 26; + h0 -= shift_left(carry0, 26); carry2 = (h2 + (i64) (1 << 25)) >> 26; h3 += carry2; - h2 -= carry2 << 26; + h2 -= shift_left(carry2, 26); carry4 = (h4 + (i64) (1 << 25)) >> 26; h5 += carry4; - h4 -= carry4 << 26; + h4 -= shift_left(carry4, 26); carry6 = (h6 + (i64) (1 << 25)) >> 26; h7 += carry6; - h6 -= carry6 << 26; + h6 -= shift_left(carry6, 26); carry8 = (h8 + (i64) (1 << 25)) >> 26; h9 += carry8; - h8 -= carry8 << 26; + h8 -= shift_left(carry8, 26); h[0] = (i32) h0; h[1] = (i32) h1; @@ -528,7 +531,6 @@ int fe_isnonzero(const fe f) { } - /* h = f * g Can overlap h with f or g. @@ -719,46 +721,46 @@ void fe_mul(fe h, const fe f, const fe g) { carry0 = (h0 + (i64) (1 << 25)) >> 26; h1 += carry0; - h0 -= carry0 << 26; + h0 -= shift_left(carry0, 26); carry4 = (h4 + (i64) (1 << 25)) >> 26; h5 += carry4; - h4 -= carry4 << 26; + h4 -= shift_left(carry4, 26); carry1 = (h1 + (i64) (1 << 24)) >> 25; h2 += carry1; - h1 -= carry1 << 25; + h1 -= shift_left(carry1, 25); carry5 = (h5 + (i64) (1 << 24)) >> 25; h6 += carry5; - h5 -= carry5 << 25; + h5 -= shift_left(carry5, 25); carry2 = (h2 + (i64) (1 << 25)) >> 26; h3 += carry2; - h2 -= carry2 << 26; + h2 -= shift_left(carry2, 26); carry6 = (h6 + (i64) (1 << 25)) >> 26; h7 += carry6; - h6 -= carry6 << 26; + h6 -= shift_left(carry6, 26); carry3 = (h3 + (i64) (1 << 24)) >> 25; h4 += carry3; - h3 -= carry3 << 25; + h3 -= shift_left(carry3, 25); carry7 = (h7 + (i64) (1 << 24)) >> 25; h8 += carry7; - h7 -= carry7 << 25; + h7 -= shift_left(carry7, 25); carry4 = (h4 + (i64) (1 << 25)) >> 26; h5 += carry4; - h4 -= carry4 << 26; + h4 -= shift_left(carry4, 26); carry8 = (h8 + (i64) (1 << 25)) >> 26; h9 += carry8; - h8 -= carry8 << 26; + h8 -= shift_left(carry8, 26); carry9 = (h9 + (i64) (1 << 24)) >> 25; h0 += carry9 * 19; - h9 -= carry9 << 25; + h9 -= shift_left(carry9, 25); carry0 = (h0 + (i64) (1 << 25)) >> 26; h1 += carry0; - h0 -= carry0 << 26; + h0 -= shift_left(carry0, 26); h[0] = (i32) h0; h[1] = (i32) h1; @@ -816,17 +818,17 @@ void fe_mul121666(fe h, fe f) { i64 carry8; i64 carry9; - carry9 = (h9 + (i64) (1<<24)) >> 25; h0 += carry9 * 19; h9 -= carry9 << 25; - carry1 = (h1 + (i64) (1<<24)) >> 25; h2 += carry1; h1 -= carry1 << 25; - carry3 = (h3 + (i64) (1<<24)) >> 25; h4 += carry3; h3 -= carry3 << 25; - carry5 = (h5 + (i64) (1<<24)) >> 25; h6 += carry5; h5 -= carry5 << 25; - carry7 = (h7 + (i64) (1<<24)) >> 25; h8 += carry7; h7 -= carry7 << 25; + carry9 = (h9 + (i64) (1<<24)) >> 25; h0 += carry9 * 19; h9 -= shift_left(carry9, 25); + carry1 = (h1 + (i64) (1<<24)) >> 25; h2 += carry1; h1 -= shift_left(carry1, 25); + carry3 = (h3 + (i64) (1<<24)) >> 25; h4 += carry3; h3 -= shift_left(carry3, 25); + carry5 = (h5 + (i64) (1<<24)) >> 25; h6 += carry5; h5 -= shift_left(carry5, 25); + carry7 = (h7 + (i64) (1<<24)) >> 25; h8 += carry7; h7 -= shift_left(carry7, 25); - carry0 = (h0 + (i64) (1<<25)) >> 26; h1 += carry0; h0 -= carry0 << 26; - carry2 = (h2 + (i64) (1<<25)) >> 26; h3 += carry2; h2 -= carry2 << 26; - carry4 = (h4 + (i64) (1<<25)) >> 26; h5 += carry4; h4 -= carry4 << 26; - carry6 = (h6 + (i64) (1<<25)) >> 26; h7 += carry6; h6 -= carry6 << 26; - carry8 = (h8 + (i64) (1<<25)) >> 26; h9 += carry8; h8 -= carry8 << 26; + carry0 = (h0 + (i64) (1<<25)) >> 26; h1 += carry0; h0 -= shift_left(carry0, 26); + carry2 = (h2 + (i64) (1<<25)) >> 26; h3 += carry2; h2 -= shift_left(carry2, 26); + carry4 = (h4 + (i64) (1<<25)) >> 26; h5 += carry4; h4 -= shift_left(carry4, 26); + carry6 = (h6 + (i64) (1<<25)) >> 26; h7 += carry6; h6 -= shift_left(carry6, 26); + carry8 = (h8 + (i64) (1<<25)) >> 26; h9 += carry8; h8 -= shift_left(carry8, 26); h[0] = h0; h[1] = h1; @@ -1088,40 +1090,40 @@ void fe_sq(fe h, const fe f) { i64 carry9; carry0 = (h0 + (i64) (1 << 25)) >> 26; h1 += carry0; - h0 -= carry0 << 26; + h0 -= shift_left(carry0, 26); carry4 = (h4 + (i64) (1 << 25)) >> 26; h5 += carry4; - h4 -= carry4 << 26; + h4 -= shift_left(carry4, 26); carry1 = (h1 + (i64) (1 << 24)) >> 25; h2 += carry1; - h1 -= carry1 << 25; + h1 -= shift_left(carry1, 25); carry5 = (h5 + (i64) (1 << 24)) >> 25; h6 += carry5; - h5 -= carry5 << 25; + h5 -= shift_left(carry5, 25); carry2 = (h2 + (i64) (1 << 25)) >> 26; h3 += carry2; - h2 -= carry2 << 26; + h2 -= shift_left(carry2, 26); carry6 = (h6 + (i64) (1 << 25)) >> 26; h7 += carry6; - h6 -= carry6 << 26; + h6 -= shift_left(carry6, 26); carry3 = (h3 + (i64) (1 << 24)) >> 25; h4 += carry3; - h3 -= carry3 << 25; + h3 -= shift_left(carry3, 25); carry7 = (h7 + (i64) (1 << 24)) >> 25; h8 += carry7; - h7 -= carry7 << 25; + h7 -= shift_left(carry7, 25); carry4 = (h4 + (i64) (1 << 25)) >> 26; h5 += carry4; - h4 -= carry4 << 26; + h4 -= shift_left(carry4, 26); carry8 = (h8 + (i64) (1 << 25)) >> 26; h9 += carry8; - h8 -= carry8 << 26; + h8 -= shift_left(carry8, 26); carry9 = (h9 + (i64) (1 << 24)) >> 25; h0 += carry9 * 19; - h9 -= carry9 << 25; + h9 -= shift_left(carry9, 25); carry0 = (h0 + (i64) (1 << 25)) >> 26; h1 += carry0; - h0 -= carry0 << 26; + h0 -= shift_left(carry0, 26); h[0] = (i32) h0; h[1] = (i32) h1; h[2] = (i32) h2; @@ -1261,40 +1263,40 @@ void fe_sq2(fe h, const fe f) { h9 += h9; carry0 = (h0 + (i64) (1 << 25)) >> 26; h1 += carry0; - h0 -= carry0 << 26; + h0 -= shift_left(carry0, 26); carry4 = (h4 + (i64) (1 << 25)) >> 26; h5 += carry4; - h4 -= carry4 << 26; + h4 -= shift_left(carry4, 26); carry1 = (h1 + (i64) (1 << 24)) >> 25; h2 += carry1; - h1 -= carry1 << 25; + h1 -= shift_left(carry1, 25); carry5 = (h5 + (i64) (1 << 24)) >> 25; h6 += carry5; - h5 -= carry5 << 25; + h5 -= shift_left(carry5, 25); carry2 = (h2 + (i64) (1 << 25)) >> 26; h3 += carry2; - h2 -= carry2 << 26; + h2 -= shift_left(carry2, 26); carry6 = (h6 + (i64) (1 << 25)) >> 26; h7 += carry6; - h6 -= carry6 << 26; + h6 -= shift_left(carry6, 26); carry3 = (h3 + (i64) (1 << 24)) >> 25; h4 += carry3; - h3 -= carry3 << 25; + h3 -= shift_left(carry3, 25); carry7 = (h7 + (i64) (1 << 24)) >> 25; h8 += carry7; - h7 -= carry7 << 25; + h7 -= shift_left(carry7, 25); carry4 = (h4 + (i64) (1 << 25)) >> 26; h5 += carry4; - h4 -= carry4 << 26; + h4 -= shift_left(carry4, 26); carry8 = (h8 + (i64) (1 << 25)) >> 26; h9 += carry8; - h8 -= carry8 << 26; + h8 -= shift_left(carry8, 26); carry9 = (h9 + (i64) (1 << 24)) >> 25; h0 += carry9 * 19; - h9 -= carry9 << 25; + h9 -= shift_left(carry9, 25); carry0 = (h0 + (i64) (1 << 25)) >> 26; h1 += carry0; - h0 -= carry0 << 26; + h0 -= shift_left(carry0, 26); h[0] = (i32) h0; h[1] = (i32) h1; h[2] = (i32) h2; @@ -1429,33 +1431,33 @@ void fe_tobytes(unsigned char *s, const fe h) { /* Goal: Output h-2^255 q, which is between 0 and 2^255-20. */ carry0 = h0 >> 26; h1 += carry0; - h0 -= carry0 << 26; + h0 -= shift_left(carry0, 26); carry1 = h1 >> 25; h2 += carry1; - h1 -= carry1 << 25; + h1 -= shift_left(carry1, 25); carry2 = h2 >> 26; h3 += carry2; - h2 -= carry2 << 26; + h2 -= shift_left(carry2, 26); carry3 = h3 >> 25; h4 += carry3; - h3 -= carry3 << 25; + h3 -= shift_left(carry3, 25); carry4 = h4 >> 26; h5 += carry4; - h4 -= carry4 << 26; + h4 -= shift_left(carry4, 26); carry5 = h5 >> 25; h6 += carry5; - h5 -= carry5 << 25; + h5 -= shift_left(carry5, 25); carry6 = h6 >> 26; h7 += carry6; - h6 -= carry6 << 26; + h6 -= shift_left(carry6, 26); carry7 = h7 >> 25; h8 += carry7; - h7 -= carry7 << 25; + h7 -= shift_left(carry7, 25); carry8 = h8 >> 26; h9 += carry8; - h8 -= carry8 << 26; + h8 -= shift_left(carry8, 26); carry9 = h9 >> 25; - h9 -= carry9 << 25; + h9 -= shift_left(carry9, 25); /* h10 = carry9 */ /* diff --git a/ed25519/src/ge.cpp b/ed25519/src/ge.cpp index c6fc00472..8bcb12fdc 100644 --- a/ed25519/src/ge.cpp +++ b/ed25519/src/ge.cpp @@ -357,9 +357,11 @@ static void cmov(ge_precomp *t, ge_precomp *u, unsigned char b) { static void select(ge_precomp *t, int pos, signed char b) { + typedef signed char schar; + typedef unsigned char uchar; ge_precomp minust; - unsigned char bnegative = negative(b); - unsigned char babs = b - (((-bnegative) & b) << 1); + unsigned char const bnegative = negative(b); + unsigned char const babs = b - schar(uchar((-bnegative) & b) << 1); fe_1(t->yplusx); fe_1(t->yminusx); fe_0(t->xy2d); diff --git a/ed25519/src/sc.cpp b/ed25519/src/sc.cpp index a6656c4d5..18b8b4771 100644 --- a/ed25519/src/sc.cpp +++ b/ed25519/src/sc.cpp @@ -25,6 +25,10 @@ static u64 load_4(const unsigned char *in) { return result; } +static inline i64 shift_left(i64 v, int s) { + return i64(u64(v) << s); +} + /* Input: s[0]+256*s[1]+...+256^63*s[63] = s @@ -122,37 +126,37 @@ void sc_reduce(unsigned char *s) { s18 = 0; carry6 = (s6 + (1 << 20)) >> 21; s7 += carry6; - s6 -= carry6 << 21; + s6 -= shift_left(carry6, 21); carry8 = (s8 + (1 << 20)) >> 21; s9 += carry8; - s8 -= carry8 << 21; + s8 -= shift_left(carry8, 21); carry10 = (s10 + (1 << 20)) >> 21; s11 += carry10; - s10 -= carry10 << 21; + s10 -= shift_left(carry10, 21); carry12 = (s12 + (1 << 20)) >> 21; s13 += carry12; - s12 -= carry12 << 21; + s12 -= shift_left(carry12, 21); carry14 = (s14 + (1 << 20)) >> 21; s15 += carry14; - s14 -= carry14 << 21; + s14 -= shift_left(carry14, 21); carry16 = (s16 + (1 << 20)) >> 21; s17 += carry16; - s16 -= carry16 << 21; + s16 -= shift_left(carry16, 21); carry7 = (s7 + (1 << 20)) >> 21; s8 += carry7; - s7 -= carry7 << 21; + s7 -= shift_left(carry7, 21); carry9 = (s9 + (1 << 20)) >> 21; s10 += carry9; - s9 -= carry9 << 21; + s9 -= shift_left(carry9, 21); carry11 = (s11 + (1 << 20)) >> 21; s12 += carry11; - s11 -= carry11 << 21; + s11 -= shift_left(carry11, 21); carry13 = (s13 + (1 << 20)) >> 21; s14 += carry13; - s13 -= carry13 << 21; + s13 -= shift_left(carry13, 21); carry15 = (s15 + (1 << 20)) >> 21; s16 += carry15; - s15 -= carry15 << 21; + s15 -= shift_left(carry15, 21); s5 += s17 * 666643; s6 += s17 * 470296; s7 += s17 * 654183; @@ -197,40 +201,40 @@ void sc_reduce(unsigned char *s) { s12 = 0; carry0 = (s0 + (1 << 20)) >> 21; s1 += carry0; - s0 -= carry0 << 21; + s0 -= shift_left(carry0, 21); carry2 = (s2 + (1 << 20)) >> 21; s3 += carry2; - s2 -= carry2 << 21; + s2 -= shift_left(carry2, 21); carry4 = (s4 + (1 << 20)) >> 21; s5 += carry4; - s4 -= carry4 << 21; + s4 -= shift_left(carry4, 21); carry6 = (s6 + (1 << 20)) >> 21; s7 += carry6; - s6 -= carry6 << 21; + s6 -= shift_left(carry6, 21); carry8 = (s8 + (1 << 20)) >> 21; s9 += carry8; - s8 -= carry8 << 21; + s8 -= shift_left(carry8, 21); carry10 = (s10 + (1 << 20)) >> 21; s11 += carry10; - s10 -= carry10 << 21; + s10 -= shift_left(carry10, 21); carry1 = (s1 + (1 << 20)) >> 21; s2 += carry1; - s1 -= carry1 << 21; + s1 -= shift_left(carry1, 21); carry3 = (s3 + (1 << 20)) >> 21; s4 += carry3; - s3 -= carry3 << 21; + s3 -= shift_left(carry3, 21); carry5 = (s5 + (1 << 20)) >> 21; s6 += carry5; - s5 -= carry5 << 21; + s5 -= shift_left(carry5, 21); carry7 = (s7 + (1 << 20)) >> 21; s8 += carry7; - s7 -= carry7 << 21; + s7 -= shift_left(carry7, 21); carry9 = (s9 + (1 << 20)) >> 21; s10 += carry9; - s9 -= carry9 << 21; + s9 -= shift_left(carry9, 21); carry11 = (s11 + (1 << 20)) >> 21; s12 += carry11; - s11 -= carry11 << 21; + s11 -= shift_left(carry11, 21); s0 += s12 * 666643; s1 += s12 * 470296; s2 += s12 * 654183; @@ -240,40 +244,40 @@ void sc_reduce(unsigned char *s) { s12 = 0; carry0 = s0 >> 21; s1 += carry0; - s0 -= carry0 << 21; + s0 -= shift_left(carry0, 21); carry1 = s1 >> 21; s2 += carry1; - s1 -= carry1 << 21; + s1 -= shift_left(carry1, 21); carry2 = s2 >> 21; s3 += carry2; - s2 -= carry2 << 21; + s2 -= shift_left(carry2, 21); carry3 = s3 >> 21; s4 += carry3; - s3 -= carry3 << 21; + s3 -= shift_left(carry3, 21); carry4 = s4 >> 21; s5 += carry4; - s4 -= carry4 << 21; + s4 -= shift_left(carry4, 21); carry5 = s5 >> 21; s6 += carry5; - s5 -= carry5 << 21; + s5 -= shift_left(carry5, 21); carry6 = s6 >> 21; s7 += carry6; - s6 -= carry6 << 21; + s6 -= shift_left(carry6, 21); carry7 = s7 >> 21; s8 += carry7; - s7 -= carry7 << 21; + s7 -= shift_left(carry7, 21); carry8 = s8 >> 21; s9 += carry8; - s8 -= carry8 << 21; + s8 -= shift_left(carry8, 21); carry9 = s9 >> 21; s10 += carry9; - s9 -= carry9 << 21; + s9 -= shift_left(carry9, 21); carry10 = s10 >> 21; s11 += carry10; - s10 -= carry10 << 21; + s10 -= shift_left(carry10, 21); carry11 = s11 >> 21; s12 += carry11; - s11 -= carry11 << 21; + s11 -= shift_left(carry11, 21); s0 += s12 * 666643; s1 += s12 * 470296; s2 += s12 * 654183; @@ -283,37 +287,37 @@ void sc_reduce(unsigned char *s) { s12 = 0; carry0 = s0 >> 21; s1 += carry0; - s0 -= carry0 << 21; + s0 -= shift_left(carry0, 21); carry1 = s1 >> 21; s2 += carry1; - s1 -= carry1 << 21; + s1 -= shift_left(carry1, 21); carry2 = s2 >> 21; s3 += carry2; - s2 -= carry2 << 21; + s2 -= shift_left(carry2, 21); carry3 = s3 >> 21; s4 += carry3; - s3 -= carry3 << 21; + s3 -= shift_left(carry3, 21); carry4 = s4 >> 21; s5 += carry4; - s4 -= carry4 << 21; + s4 -= shift_left(carry4, 21); carry5 = s5 >> 21; s6 += carry5; - s5 -= carry5 << 21; + s5 -= shift_left(carry5, 21); carry6 = s6 >> 21; s7 += carry6; - s6 -= carry6 << 21; + s6 -= shift_left(carry6, 21); carry7 = s7 >> 21; s8 += carry7; - s7 -= carry7 << 21; + s7 -= shift_left(carry7, 21); carry8 = s8 >> 21; s9 += carry8; - s8 -= carry8 << 21; + s8 -= shift_left(carry8, 21); carry9 = s9 >> 21; s10 += carry9; - s9 -= carry9 << 21; + s9 -= shift_left(carry9, 21); carry10 = s10 >> 21; s11 += carry10; - s10 -= carry10 << 21; + s10 -= shift_left(carry10, 21); s[0] = (unsigned char) ((s0 >> 0) & 0xff); s[1] = (unsigned char) ((s0 >> 8) & 0xff); @@ -473,73 +477,73 @@ void sc_muladd(unsigned char *s, const unsigned char *a, const unsigned char *b, s23 = 0; carry0 = (s0 + (1 << 20)) >> 21; s1 += carry0; - s0 -= carry0 << 21; + s0 -= shift_left(carry0, 21); carry2 = (s2 + (1 << 20)) >> 21; s3 += carry2; - s2 -= carry2 << 21; + s2 -= shift_left(carry2, 21); carry4 = (s4 + (1 << 20)) >> 21; s5 += carry4; - s4 -= carry4 << 21; + s4 -= shift_left(carry4, 21); carry6 = (s6 + (1 << 20)) >> 21; s7 += carry6; - s6 -= carry6 << 21; + s6 -= shift_left(carry6, 21); carry8 = (s8 + (1 << 20)) >> 21; s9 += carry8; - s8 -= carry8 << 21; + s8 -= shift_left(carry8, 21); carry10 = (s10 + (1 << 20)) >> 21; s11 += carry10; - s10 -= carry10 << 21; + s10 -= shift_left(carry10, 21); carry12 = (s12 + (1 << 20)) >> 21; s13 += carry12; - s12 -= carry12 << 21; + s12 -= shift_left(carry12, 21); carry14 = (s14 + (1 << 20)) >> 21; s15 += carry14; - s14 -= carry14 << 21; + s14 -= shift_left(carry14, 21); carry16 = (s16 + (1 << 20)) >> 21; s17 += carry16; - s16 -= carry16 << 21; + s16 -= shift_left(carry16, 21); carry18 = (s18 + (1 << 20)) >> 21; s19 += carry18; - s18 -= carry18 << 21; + s18 -= shift_left(carry18, 21); carry20 = (s20 + (1 << 20)) >> 21; s21 += carry20; - s20 -= carry20 << 21; + s20 -= shift_left(carry20, 21); carry22 = (s22 + (1 << 20)) >> 21; s23 += carry22; - s22 -= carry22 << 21; + s22 -= shift_left(carry22, 21); carry1 = (s1 + (1 << 20)) >> 21; s2 += carry1; - s1 -= carry1 << 21; + s1 -= shift_left(carry1, 21); carry3 = (s3 + (1 << 20)) >> 21; s4 += carry3; - s3 -= carry3 << 21; + s3 -= shift_left(carry3, 21); carry5 = (s5 + (1 << 20)) >> 21; s6 += carry5; - s5 -= carry5 << 21; + s5 -= shift_left(carry5, 21); carry7 = (s7 + (1 << 20)) >> 21; s8 += carry7; - s7 -= carry7 << 21; + s7 -= shift_left(carry7, 21); carry9 = (s9 + (1 << 20)) >> 21; s10 += carry9; - s9 -= carry9 << 21; + s9 -= shift_left(carry9, 21); carry11 = (s11 + (1 << 20)) >> 21; s12 += carry11; - s11 -= carry11 << 21; + s11 -= shift_left(carry11, 21); carry13 = (s13 + (1 << 20)) >> 21; s14 += carry13; - s13 -= carry13 << 21; + s13 -= shift_left(carry13, 21); carry15 = (s15 + (1 << 20)) >> 21; s16 += carry15; - s15 -= carry15 << 21; + s15 -= shift_left(carry15, 21); carry17 = (s17 + (1 << 20)) >> 21; s18 += carry17; - s17 -= carry17 << 21; + s17 -= shift_left(carry17, 21); carry19 = (s19 + (1 << 20)) >> 21; s20 += carry19; - s19 -= carry19 << 21; + s19 -= shift_left(carry19, 21); carry21 = (s21 + (1 << 20)) >> 21; s22 += carry21; - s21 -= carry21 << 21; + s21 -= shift_left(carry21, 21); s11 += s23 * 666643; s12 += s23 * 470296; s13 += s23 * 654183; @@ -584,37 +588,37 @@ void sc_muladd(unsigned char *s, const unsigned char *a, const unsigned char *b, s18 = 0; carry6 = (s6 + (1 << 20)) >> 21; s7 += carry6; - s6 -= carry6 << 21; + s6 -= shift_left(carry6, 21); carry8 = (s8 + (1 << 20)) >> 21; s9 += carry8; - s8 -= carry8 << 21; + s8 -= shift_left(carry8, 21); carry10 = (s10 + (1 << 20)) >> 21; s11 += carry10; - s10 -= carry10 << 21; + s10 -= shift_left(carry10, 21); carry12 = (s12 + (1 << 20)) >> 21; s13 += carry12; - s12 -= carry12 << 21; + s12 -= shift_left(carry12, 21); carry14 = (s14 + (1 << 20)) >> 21; s15 += carry14; - s14 -= carry14 << 21; + s14 -= shift_left(carry14, 21); carry16 = (s16 + (1 << 20)) >> 21; s17 += carry16; - s16 -= carry16 << 21; + s16 -= shift_left(carry16, 21); carry7 = (s7 + (1 << 20)) >> 21; s8 += carry7; - s7 -= carry7 << 21; + s7 -= shift_left(carry7, 21); carry9 = (s9 + (1 << 20)) >> 21; s10 += carry9; - s9 -= carry9 << 21; + s9 -= shift_left(carry9, 21); carry11 = (s11 + (1 << 20)) >> 21; s12 += carry11; - s11 -= carry11 << 21; + s11 -= shift_left(carry11, 21); carry13 = (s13 + (1 << 20)) >> 21; s14 += carry13; - s13 -= carry13 << 21; + s13 -= shift_left(carry13, 21); carry15 = (s15 + (1 << 20)) >> 21; s16 += carry15; - s15 -= carry15 << 21; + s15 -= shift_left(carry15, 21); s5 += s17 * 666643; s6 += s17 * 470296; s7 += s17 * 654183; @@ -659,40 +663,40 @@ void sc_muladd(unsigned char *s, const unsigned char *a, const unsigned char *b, s12 = 0; carry0 = (s0 + (1 << 20)) >> 21; s1 += carry0; - s0 -= carry0 << 21; + s0 -= shift_left(carry0, 21); carry2 = (s2 + (1 << 20)) >> 21; s3 += carry2; - s2 -= carry2 << 21; + s2 -= shift_left(carry2, 21); carry4 = (s4 + (1 << 20)) >> 21; s5 += carry4; - s4 -= carry4 << 21; + s4 -= shift_left(carry4, 21); carry6 = (s6 + (1 << 20)) >> 21; s7 += carry6; - s6 -= carry6 << 21; + s6 -= shift_left(carry6, 21); carry8 = (s8 + (1 << 20)) >> 21; s9 += carry8; - s8 -= carry8 << 21; + s8 -= shift_left(carry8, 21); carry10 = (s10 + (1 << 20)) >> 21; s11 += carry10; - s10 -= carry10 << 21; + s10 -= shift_left(carry10, 21); carry1 = (s1 + (1 << 20)) >> 21; s2 += carry1; - s1 -= carry1 << 21; + s1 -= shift_left(carry1, 21); carry3 = (s3 + (1 << 20)) >> 21; s4 += carry3; - s3 -= carry3 << 21; + s3 -= shift_left(carry3, 21); carry5 = (s5 + (1 << 20)) >> 21; s6 += carry5; - s5 -= carry5 << 21; + s5 -= shift_left(carry5, 21); carry7 = (s7 + (1 << 20)) >> 21; s8 += carry7; - s7 -= carry7 << 21; + s7 -= shift_left(carry7, 21); carry9 = (s9 + (1 << 20)) >> 21; s10 += carry9; - s9 -= carry9 << 21; + s9 -= shift_left(carry9, 21); carry11 = (s11 + (1 << 20)) >> 21; s12 += carry11; - s11 -= carry11 << 21; + s11 -= shift_left(carry11, 21); s0 += s12 * 666643; s1 += s12 * 470296; s2 += s12 * 654183; @@ -702,40 +706,40 @@ void sc_muladd(unsigned char *s, const unsigned char *a, const unsigned char *b, s12 = 0; carry0 = s0 >> 21; s1 += carry0; - s0 -= carry0 << 21; + s0 -= shift_left(carry0, 21); carry1 = s1 >> 21; s2 += carry1; - s1 -= carry1 << 21; + s1 -= shift_left(carry1, 21); carry2 = s2 >> 21; s3 += carry2; - s2 -= carry2 << 21; + s2 -= shift_left(carry2, 21); carry3 = s3 >> 21; s4 += carry3; - s3 -= carry3 << 21; + s3 -= shift_left(carry3, 21); carry4 = s4 >> 21; s5 += carry4; - s4 -= carry4 << 21; + s4 -= shift_left(carry4, 21); carry5 = s5 >> 21; s6 += carry5; - s5 -= carry5 << 21; + s5 -= shift_left(carry5, 21); carry6 = s6 >> 21; s7 += carry6; - s6 -= carry6 << 21; + s6 -= shift_left(carry6, 21); carry7 = s7 >> 21; s8 += carry7; - s7 -= carry7 << 21; + s7 -= shift_left(carry7, 21); carry8 = s8 >> 21; s9 += carry8; - s8 -= carry8 << 21; + s8 -= shift_left(carry8, 21); carry9 = s9 >> 21; s10 += carry9; - s9 -= carry9 << 21; + s9 -= shift_left(carry9, 21); carry10 = s10 >> 21; s11 += carry10; - s10 -= carry10 << 21; + s10 -= shift_left(carry10, 21); carry11 = s11 >> 21; s12 += carry11; - s11 -= carry11 << 21; + s11 -= shift_left(carry11, 21); s0 += s12 * 666643; s1 += s12 * 470296; s2 += s12 * 654183; @@ -745,37 +749,37 @@ void sc_muladd(unsigned char *s, const unsigned char *a, const unsigned char *b, s12 = 0; carry0 = s0 >> 21; s1 += carry0; - s0 -= carry0 << 21; + s0 -= shift_left(carry0, 21); carry1 = s1 >> 21; s2 += carry1; - s1 -= carry1 << 21; + s1 -= shift_left(carry1, 21); carry2 = s2 >> 21; s3 += carry2; - s2 -= carry2 << 21; + s2 -= shift_left(carry2, 21); carry3 = s3 >> 21; s4 += carry3; - s3 -= carry3 << 21; + s3 -= shift_left(carry3, 21); carry4 = s4 >> 21; s5 += carry4; - s4 -= carry4 << 21; + s4 -= shift_left(carry4, 21); carry5 = s5 >> 21; s6 += carry5; - s5 -= carry5 << 21; + s5 -= shift_left(carry5, 21); carry6 = s6 >> 21; s7 += carry6; - s6 -= carry6 << 21; + s6 -= shift_left(carry6, 21); carry7 = s7 >> 21; s8 += carry7; - s7 -= carry7 << 21; + s7 -= shift_left(carry7, 21); carry8 = s8 >> 21; s9 += carry8; - s8 -= carry8 << 21; + s8 -= shift_left(carry8, 21); carry9 = s9 >> 21; s10 += carry9; - s9 -= carry9 << 21; + s9 -= shift_left(carry9, 21); carry10 = s10 >> 21; s11 += carry10; - s10 -= carry10 << 21; + s10 -= shift_left(carry10, 21); s[0] = (unsigned char) ((s0 >> 0) & 0xff); s[1] = (unsigned char) ((s0 >> 8) & 0xff); diff --git a/examples/connection_tester.cpp b/examples/connection_tester.cpp index c6f97b25c..e786625d3 100644 --- a/examples/connection_tester.cpp +++ b/examples/connection_tester.cpp @@ -849,7 +849,8 @@ void generate_data(char const* path, torrent_info const& ti) for (int j = 0; j < ti.piece_size(i); j += 0x4000) { generate_block(piece, i, j, 0x4000); - file::iovec_t b = { piece, 0x4000}; + int const left_in_piece = ti.piece_size(i) - j; + file::iovec_t const b = { piece, size_t(std::min(left_in_piece, 0x4000))}; storage_error error; st->writev(b, i, j, 0, error); if (error) diff --git a/src/disk_io_thread.cpp b/src/disk_io_thread.cpp index a43b596d0..a07cd3412 100644 --- a/src/disk_io_thread.cpp +++ b/src/disk_io_thread.cpp @@ -89,7 +89,6 @@ namespace libtorrent void debug_log(char const* fmt, ...) { -#if DEBUG_DISK_THREAD static std::mutex log_mutex; static const time_point start = clock_type::now(); va_list v; @@ -113,14 +112,10 @@ namespace libtorrent prepend_time = (usr[len-1] == '\n'); std::unique_lock l(log_mutex); fputs(buf, stderr); -#else - TORRENT_UNUSED(fmt); -#endif } #endif // DEBUG_DISK_THREAD - int file_flags_for_job(disk_io_job* j , bool const coalesce_buffers) { diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 4dff12c49..f94c24166 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -6426,8 +6426,7 @@ namespace aux { int const disconnect = std::min(to_disconnect, num - my_average); to_disconnect -= disconnect; - t.second->disconnect_peers(disconnect - , error_code(errors::too_many_connections)); + t.second->disconnect_peers(disconnect, errors::too_many_connections); } } } diff --git a/src/socks5_stream.cpp b/src/socks5_stream.cpp index 9df62a2cc..44f8cae3f 100644 --- a/src/socks5_stream.cpp +++ b/src/socks5_stream.cpp @@ -74,7 +74,7 @@ namespace libtorrent { return boost::system::error_condition(ev, *this); } }; - TORRENT_EXPORT boost::system::error_category& socks_category() + boost::system::error_category& socks_category() { static socks_error_category cat; return cat; diff --git a/src/torrent.cpp b/src/torrent.cpp index fb9294e19..68ace0e07 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -924,14 +924,15 @@ namespace libtorrent // since the call to disconnect_if_redundant() may // delete the entry from this container, make sure // to increment the iterator early - bt_peer_connection* p = static_cast(*i); + peer_connection* p = *i; if (p->type() == connection_type::bittorrent) { - std::shared_ptr me(p->self()); - if (!p->is_disconnecting()) + bt_peer_connection* btp = static_cast(p); + std::shared_ptr me(btp->self()); + if (!btp->is_disconnecting()) { - p->send_not_interested(); - p->write_upload_only(); + btp->send_not_interested(); + btp->write_upload_only(); } } diff --git a/src/utp_stream.cpp b/src/utp_stream.cpp index 83885ed7c..8f7b94087 100644 --- a/src/utp_stream.cpp +++ b/src/utp_stream.cpp @@ -769,7 +769,7 @@ void utp_socket_impl::update_mtu_limits() m_mtu = (m_mtu_floor + m_mtu_ceiling) / 2; - if ((m_cwnd >> 16) < m_mtu) m_cwnd = std::int64_t(m_mtu) << 16; + if ((m_cwnd >> 16) < m_mtu) m_cwnd = std::int64_t(m_mtu) * (1 << 16); UTP_LOGV("%8p: updating MTU to: %d [%d, %d]\n" , static_cast(this), m_mtu, m_mtu_floor, m_mtu_ceiling); @@ -2291,7 +2291,8 @@ void utp_socket_impl::experienced_loss(int const seq_nr) if (compare_less_wrap(seq_nr, m_loss_seq_nr + 1, ACK_MASK)) return; // cut window size in 2 - m_cwnd = (std::max)(m_cwnd * m_sm->loss_multiplier() / 100, std::int64_t(m_mtu << 16)); + m_cwnd = (std::max)(m_cwnd * m_sm->loss_multiplier() / 100 + , std::int64_t(m_mtu) * (1 << 16)); m_loss_seq_nr = m_seq_nr; UTP_LOGV("%8p: Lost packet %d caused cwnd cut\n", static_cast(this), seq_nr); @@ -2652,7 +2653,7 @@ void utp_socket_impl::init_mtu(int link_mtu, int utp_mtu) // if the window size is smaller than one packet size // set it to one - if ((m_cwnd >> 16) < m_mtu) m_cwnd = std::int64_t(m_mtu) << 16; + if ((m_cwnd >> 16) < m_mtu) m_cwnd = std::int64_t(m_mtu) * (1 << 16); UTP_LOGV("%8p: initializing MTU to: %d [%d, %d]\n" , static_cast(this), m_mtu, m_mtu_floor, m_mtu_ceiling); @@ -3377,8 +3378,8 @@ void utp_socket_impl::do_ledbat(const int acked_bytes, const int delay const bool cwnd_saturated = (m_bytes_in_flight + acked_bytes + m_mtu > (m_cwnd >> 16)); // all of these are fixed points with 16 bits fraction portion - const std::int64_t window_factor = (std::int64_t(acked_bytes) << 16) / in_flight; - const std::int64_t delay_factor = (std::int64_t(target_delay - delay) << 16) / target_delay; + const std::int64_t window_factor = (std::int64_t(acked_bytes) * (1 << 16)) / in_flight; + const std::int64_t delay_factor = (std::int64_t(target_delay - delay) * (1 << 16)) / target_delay; std::int64_t scaled_gain; if (delay >= target_delay) @@ -3405,7 +3406,7 @@ void utp_socket_impl::do_ledbat(const int acked_bytes, const int delay // congestion window), don't adjust it at all. if (cwnd_saturated) { - std::int64_t exponential_gain = std::int64_t(acked_bytes) << 16; + std::int64_t exponential_gain = std::int64_t(acked_bytes) * (1 << 16); if (m_slow_start) { // mimic TCP slow-start by adding the number of acked @@ -3576,13 +3577,13 @@ void utp_socket_impl::tick(time_point now) { // this is just a timeout because this direction of // the stream is idle. Don't reset the cwnd, just decay it - m_cwnd = (std::max)(m_cwnd * 2 / 3, std::int64_t(m_mtu) << 16); + m_cwnd = std::max(m_cwnd * 2 / 3, std::int64_t(m_mtu) * (1 << 16)); } else { // we timed out because a packet was not ACKed or because // the cwnd was made smaller than one packet - m_cwnd = std::int64_t(m_mtu) << 16; + m_cwnd = std::int64_t(m_mtu) * (1 << 16); } TORRENT_ASSERT(m_cwnd >= 0); diff --git a/test/main.cpp b/test/main.cpp index 3b3b085c0..be6c327d1 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -70,7 +70,8 @@ using namespace libtorrent; // out, such as the log int old_stdout = -1; int old_stderr = -1; -bool redirect_output = true; +bool redirect_stdout = true; +bool redirect_stderr = true; bool keep_files = false; extern int _g_test_idx; @@ -81,7 +82,7 @@ unit_test_t* current_test = nullptr; void output_test_log_to_terminal() { if (current_test == nullptr || old_stdout == -1 || old_stderr == -1 - || !redirect_output || current_test->output == nullptr) + || !redirect_stdout || current_test->output == nullptr) return; fflush(stdout); @@ -95,7 +96,7 @@ void output_test_log_to_terminal() int size = 0; do { size = int(fread(buf, 1, sizeof(buf), current_test->output)); - if (size > 0) fwrite(buf, 1, size, stderr); + if (size > 0) fwrite(buf, 1, size, stdout); } while (size > 0); } @@ -203,13 +204,17 @@ void print_usage(char const* executable) std::printf("%s [options] [tests...]\n" "\n" "OPTIONS:\n" - "-h,--help show this help\n" - "-l,--list list the tests available to run\n" - "-k,--keep keep files created by the test\n" - " regardless of whether it passed or not\n" - "-n,--no-redirect don't redirect test output to\n" - " temporary file, but let it go straight\n" - " to stdout\n" + "-h,--help show this help\n" + "-l,--list list the tests available to run\n" + "-k,--keep keep files created by the test\n" + " regardless of whether it passed or not\n" + "-n,--no-redirect don't redirect test output to\n" + " temporary file, but let it go straight\n" + " to stdout\n" + "--no-stderr-redirect don't redirect stderr, but still redirect\n" + " stdout. This is useful when building with\n" + " sanitizers, which rely on being able to print\n" + " to stderr and exit\n" "\n" "for tests, specify one or more test names as printed\n" "by -l. If no test is specified, all tests are run\n", executable); @@ -243,7 +248,13 @@ EXPORT int main(int argc, char const* argv[]) if (strcmp(argv[0], "-n") == 0 || strcmp(argv[0], "--no-redirect") == 0) { - redirect_output = false; + redirect_stdout = false; + redirect_stderr = false; + } + + if (strcmp(argv[0], "--no-stderr-redirect") == 0) + { + redirect_stderr = false; } if (strcmp(argv[0], "-k") == 0 || strcmp(argv[0], "--keep") == 0) @@ -341,11 +352,8 @@ EXPORT int main(int argc, char const* argv[]) return 1; } - if (redirect_output) - { - old_stdout = dup(fileno(stdout)); - old_stderr = dup(fileno(stderr)); - } + if (redirect_stdout) old_stdout = dup(fileno(stdout)); + if (redirect_stderr) old_stderr = dup(fileno(stderr)); int num_run = 0; for (int i = 0; i < _g_num_unit_tests; ++i) @@ -355,7 +363,7 @@ EXPORT int main(int argc, char const* argv[]) unit_test_t& t = _g_unit_tests[i]; - if (redirect_output) + if (redirect_stdout) { // redirect test output to a temporary file fflush(stdout); @@ -365,7 +373,7 @@ EXPORT int main(int argc, char const* argv[]) if (f != nullptr) { int ret1 = dup2(fileno(f), fileno(stdout)); - dup2(fileno(f), fileno(stderr)); + if (redirect_stderr) dup2(fileno(f), fileno(stderr)); if (ret1 >= 0) { t.output = f; @@ -432,17 +440,12 @@ EXPORT int main(int argc, char const* argv[]) total_failures += _g_test_failures; ++num_run; - if (redirect_output && t.output) - { + if (redirect_stdout && t.output) fclose(t.output); - } } - if (redirect_output) - { - dup2(old_stdout, fileno(stdout)); - dup2(old_stderr, fileno(stderr)); - } + if (redirect_stdout) dup2(old_stdout, fileno(stdout)); + if (redirect_stderr) dup2(old_stderr, fileno(stderr)); if (!tests_to_run.empty()) { @@ -468,11 +471,8 @@ EXPORT int main(int argc, char const* argv[]) stop_peer(); stop_dht(); - if (redirect_output) - { - fflush(stdout); - fflush(stderr); - } + if (redirect_stdout) fflush(stdout); + if (redirect_stderr) fflush(stderr); ret = print_failures(); #if !defined TORRENT_LOGGING diff --git a/test/test_bdecode.cpp b/test/test_bdecode.cpp index c59025cf0..74f3b3da6 100644 --- a/test/test_bdecode.cpp +++ b/test/test_bdecode.cpp @@ -365,7 +365,7 @@ TORRENT_TEST(bdecode_error) error_code ec(bdecode_errors::overflow); TEST_EQUAL(ec.message(), "integer overflow"); TEST_EQUAL(ec.category().name(), std::string("bdecode error")); - ec.assign(5434, get_bdecode_category()); + ec.assign(5434, bdecode_category()); TEST_EQUAL(ec.message(), "Unknown error"); } @@ -448,8 +448,7 @@ TORRENT_TEST(depth_limit) error_code ec; int ret = bdecode(b, b + sizeof(b), e, ec, nullptr, 100); TEST_CHECK(ret != 0); - TEST_EQUAL(ec, error_code(bdecode_errors::depth_exceeded - , get_bdecode_category())); + TEST_EQUAL(ec, error_code(bdecode_errors::depth_exceeded)); } // test the item limit @@ -466,8 +465,7 @@ TORRENT_TEST(item_limit) error_code ec; int ret = bdecode(b, b + i + 1, e, ec, nullptr, 1000, 1000); TEST_CHECK(ret != 0); - TEST_EQUAL(ec, error_code(bdecode_errors::limit_exceeded - , get_bdecode_category())); + TEST_EQUAL(ec, error_code(bdecode_errors::limit_exceeded)); } // test unexpected EOF diff --git a/test/test_bencoding.cpp b/test/test_bencoding.cpp index e97d35d35..6286f92a8 100644 --- a/test/test_bencoding.cpp +++ b/test/test_bencoding.cpp @@ -240,8 +240,7 @@ TORRENT_TEST(lazy_entry) int ret = lazy_bdecode(b, b + sizeof(b)-1, e, ec); TEST_CHECK(ret != 0); std::printf("%s\n", print_entry(e).c_str()); - TEST_CHECK(ec == error_code(bdecode_errors::expected_value - , get_bdecode_category())); + TEST_EQUAL(ec, error_code(bdecode_errors::expected_value)); } // test strings with overflow length-prefix @@ -252,8 +251,7 @@ TORRENT_TEST(lazy_entry) int ret = lazy_bdecode(b, b + sizeof(b)-1, e, ec); TEST_CHECK(ret != 0); std::printf("%s\n", print_entry(e).c_str()); - TEST_CHECK(ec == error_code(bdecode_errors::overflow - , get_bdecode_category())); + TEST_EQUAL(ec, error_code(bdecode_errors::overflow)); } // test integers that don't fit in 64 bits @@ -330,8 +328,7 @@ TORRENT_TEST(lazy_entry) error_code ec; int ret = lazy_bdecode(b, b + sizeof(b), e, ec); TEST_CHECK(ret != 0); - TEST_EQUAL(ec, error_code(bdecode_errors::depth_exceeded - , get_bdecode_category())); + TEST_EQUAL(ec, error_code(bdecode_errors::depth_exceeded)); } // test the item limit @@ -347,8 +344,7 @@ TORRENT_TEST(lazy_entry) error_code ec; int ret = lazy_bdecode(b, b + i + 1, e, ec, nullptr, 1000, 1000); TEST_CHECK(ret != 0); - TEST_EQUAL(ec, error_code(bdecode_errors::limit_exceeded - , get_bdecode_category())); + TEST_EQUAL(ec, error_code(bdecode_errors::limit_exceeded)); } // test unexpected EOF @@ -360,8 +356,7 @@ TORRENT_TEST(lazy_entry) int ret = lazy_bdecode(b, b + sizeof(b)-1, e, ec, nullptr); TEST_CHECK(ret != 0); std::printf("%s\n", print_entry(e).c_str()); - TEST_EQUAL(ec, error_code(bdecode_errors::unexpected_eof - , get_bdecode_category())); + TEST_EQUAL(ec, error_code(bdecode_errors::unexpected_eof)); } // test unexpected EOF (really expected terminator) @@ -373,8 +368,7 @@ TORRENT_TEST(lazy_entry) int ret = lazy_bdecode(b, b + sizeof(b)-1, e, ec, nullptr); TEST_CHECK(ret != 0); std::printf("%s\n", print_entry(e).c_str()); - TEST_EQUAL(ec, error_code(bdecode_errors::unexpected_eof - , get_bdecode_category())); + TEST_EQUAL(ec, error_code(bdecode_errors::unexpected_eof)); } // test expected string @@ -387,8 +381,7 @@ TORRENT_TEST(lazy_entry) int ret = lazy_bdecode(b, b + sizeof(b)-1, e, ec, nullptr); TEST_CHECK(ret != 0); std::printf("%s\n", print_entry(e).c_str()); - TEST_EQUAL(ec, error_code(bdecode_errors::expected_digit - , get_bdecode_category())); + TEST_EQUAL(ec, error_code(bdecode_errors::expected_digit)); } // test unexpected EOF while parsing dict key @@ -400,8 +393,7 @@ TORRENT_TEST(lazy_entry) int ret = lazy_bdecode(b, b + sizeof(b)-1, e, ec, nullptr); TEST_CHECK(ret != 0); std::printf("%s\n", print_entry(e).c_str()); - TEST_EQUAL(ec, error_code(bdecode_errors::unexpected_eof - , get_bdecode_category())); + TEST_EQUAL(ec, error_code(bdecode_errors::unexpected_eof)); } // test unexpected EOF while parsing dict key @@ -413,8 +405,7 @@ TORRENT_TEST(lazy_entry) int ret = lazy_bdecode(b, b + sizeof(b)-1, e, ec, nullptr); TEST_CHECK(ret != 0); std::printf("%s\n", print_entry(e).c_str()); - TEST_EQUAL(ec, error_code(bdecode_errors::unexpected_eof - , get_bdecode_category())); + TEST_EQUAL(ec, error_code(bdecode_errors::unexpected_eof)); } // test expected string while parsing dict key @@ -426,8 +417,7 @@ TORRENT_TEST(lazy_entry) int ret = lazy_bdecode(b, b + sizeof(b)-1, e, ec, nullptr); TEST_CHECK(ret != 0); std::printf("%s\n", print_entry(e).c_str()); - TEST_EQUAL(ec, error_code(bdecode_errors::expected_digit - , get_bdecode_category())); + TEST_EQUAL(ec, error_code(bdecode_errors::expected_digit)); } // test unexpected EOF while parsing int @@ -439,8 +429,7 @@ TORRENT_TEST(lazy_entry) int ret = lazy_bdecode(b, b + sizeof(b)-1, e, ec, nullptr); TEST_CHECK(ret != 0); std::printf("%s\n", print_entry(e).c_str()); - TEST_EQUAL(ec, error_code(bdecode_errors::unexpected_eof - , get_bdecode_category())); + TEST_EQUAL(ec, error_code(bdecode_errors::unexpected_eof)); } // test unexpected EOF while parsing int @@ -452,8 +441,7 @@ TORRENT_TEST(lazy_entry) int ret = lazy_bdecode(b, b + sizeof(b)-1, e, ec, nullptr); TEST_CHECK(ret != 0); std::printf("%s\n", print_entry(e).c_str()); - TEST_EQUAL(ec, error_code(bdecode_errors::unexpected_eof - , get_bdecode_category())); + TEST_EQUAL(ec, error_code(bdecode_errors::unexpected_eof)); } @@ -466,8 +454,7 @@ TORRENT_TEST(lazy_entry) int ret = lazy_bdecode(b, b + sizeof(b)-1, e, ec, nullptr); TEST_CHECK(ret != 0); std::printf("%s\n", print_entry(e).c_str()); - TEST_EQUAL(ec, error_code(bdecode_errors::expected_colon - , get_bdecode_category())); + TEST_EQUAL(ec, error_code(bdecode_errors::expected_colon)); } // test empty string @@ -478,8 +465,7 @@ TORRENT_TEST(lazy_entry) error_code ec; int ret = lazy_bdecode(b, b + sizeof(b)-1, e, ec, nullptr); TEST_EQUAL(ret, -1); - TEST_EQUAL(ec, error_code(bdecode_errors::unexpected_eof - , get_bdecode_category())); + TEST_EQUAL(ec, error_code(bdecode_errors::unexpected_eof)); std::printf("%s\n", print_entry(e).c_str()); } @@ -492,8 +478,7 @@ TORRENT_TEST(lazy_entry) int ret = lazy_bdecode(b, b + sizeof(b)-1, e, ec, nullptr); TEST_CHECK(ret != 0); std::printf("%s\n", print_entry(e).c_str()); - TEST_EQUAL(ec, error_code(bdecode_errors::unexpected_eof - , get_bdecode_category())); + TEST_EQUAL(ec, error_code(bdecode_errors::unexpected_eof)); } // test pascal string dict diff --git a/test/test_ed25519.cpp b/test/test_ed25519.cpp index a3c701e69..971e51304 100644 --- a/test/test_ed25519.cpp +++ b/test/test_ed25519.cpp @@ -286,3 +286,4 @@ TORRENT_TEST(empty) TEST_CHECK(true); } #endif // TORRENT_DISABLE_DHT +