diff --git a/depends/packages/bdb.mk b/depends/packages/bdb.mk index 6a8de3922113..b57858376418 100644 --- a/depends/packages/bdb.mk +++ b/depends/packages/bdb.mk @@ -13,7 +13,6 @@ $(package)_cflags+=-Wno-error=implicit-function-declaration -Wno-error=format-se $(package)_cxxflags+=-std=c++17 $(package)_cppflags_freebsd=-D_XOPEN_SOURCE=600 -D__BSD_VISIBLE=1 $(package)_cppflags_netbsd=-D_XOPEN_SOURCE=600 -$(package)_cppflags_openbsd=-D_XOPEN_SOURCE=600 $(package)_cppflags_mingw32=-DUNICODE -D_UNICODE endef diff --git a/doc/developer-notes.md b/doc/developer-notes.md index 5d6fd6d420e8..36c0112534fa 100644 --- a/doc/developer-notes.md +++ b/doc/developer-notes.md @@ -326,7 +326,7 @@ produce better debugging builds. ### Show sources in debugging If you have ccache enabled, absolute paths are stripped from debug information -with the -fdebug-prefix-map and -fmacro-prefix-map options (if supported by the +with the `-fdebug-prefix-map` and `-fmacro-prefix-map` options (if supported by the compiler). This might break source file detection in case you move binaries after compilation, debug from the directory other than the project root or use an IDE that only supports absolute paths for debugging. diff --git a/src/Makefile.test.include b/src/Makefile.test.include index 9c7a0a4a249e..1a4cc323e292 100644 --- a/src/Makefile.test.include +++ b/src/Makefile.test.include @@ -367,7 +367,9 @@ dash_test_check: $(TEST_BINARY) FORCE dash_test_clean : FORCE rm -f $(CLEAN_BITCOIN_TEST) $(test_test_dash_OBJECTS) $(TEST_BINARY) -check-local: $(BITCOIN_TESTS:.cpp=.cpp.test) +check-unit: $(BITCOIN_TESTS:.cpp=.cpp.test) + +check-local: check-unit if BUILD_BITCOIN_TX @echo "Running test/util/bitcoin-util-test.py..." $(PYTHON) $(top_builddir)/test/util/bitcoin-util-test.py diff --git a/src/addrman.cpp b/src/addrman.cpp index 95bf5eb9c693..835b9aa6fe46 100644 --- a/src/addrman.cpp +++ b/src/addrman.cpp @@ -581,11 +581,10 @@ bool AddrManImpl::AddSingle(const CAddress& addr, const CNetAddr& source, int64_ return false; // stochastic test: previous nRefCount == N: 2^N times harder to increase it - int nFactor = 1; - for (int n = 0; n < pinfo->nRefCount; n++) - nFactor *= 2; - if (nFactor > 1 && (insecure_rand.randrange(nFactor) != 0)) - return false; + if (pinfo->nRefCount > 0) { + const int nFactor{1 << pinfo->nRefCount}; + if (insecure_rand.randrange(nFactor) != 0) return false; + } } else { pinfo = Create(addr, source, &nId); pinfo->nTime = std::max((int64_t)0, (int64_t)pinfo->nTime - nTimePenalty); diff --git a/src/crc32c/src/crc32c_arm64.cc b/src/crc32c/src/crc32c_arm64.cc index 1da04ed34a3c..711616cd2f53 100644 --- a/src/crc32c/src/crc32c_arm64.cc +++ b/src/crc32c/src/crc32c_arm64.cc @@ -12,6 +12,7 @@ #include #include +#include #include "./crc32c_internal.h" #ifdef CRC32C_HAVE_CONFIG_H @@ -29,14 +30,14 @@ // compute 8bytes for each segment parallelly #define CRC32C32BYTES(P, IND) \ do { \ - crc1 = __crc32cd( \ - crc1, *((const uint64_t *)(P) + (SEGMENTBYTES / 8) * 1 + (IND))); \ - crc2 = __crc32cd( \ - crc2, *((const uint64_t *)(P) + (SEGMENTBYTES / 8) * 2 + (IND))); \ - crc3 = __crc32cd( \ - crc3, *((const uint64_t *)(P) + (SEGMENTBYTES / 8) * 3 + (IND))); \ - crc0 = __crc32cd( \ - crc0, *((const uint64_t *)(P) + (SEGMENTBYTES / 8) * 0 + (IND))); \ + std::memcpy(&d64, (P) + SEGMENTBYTES * 1 + (IND) * 8, sizeof(d64)); \ + crc1 = __crc32cd(crc1, d64); \ + std::memcpy(&d64, (P) + SEGMENTBYTES * 2 + (IND) * 8, sizeof(d64)); \ + crc2 = __crc32cd(crc2, d64); \ + std::memcpy(&d64, (P) + SEGMENTBYTES * 3 + (IND) * 8, sizeof(d64)); \ + crc3 = __crc32cd(crc3, d64); \ + std::memcpy(&d64, (P) + SEGMENTBYTES * 0 + (IND) * 8, sizeof(d64)); \ + crc0 = __crc32cd(crc0, d64); \ } while (0); // compute 8*8 bytes for each segment parallelly @@ -68,6 +69,9 @@ uint32_t ExtendArm64(uint32_t crc, const uint8_t *data, size_t size) { int64_t length = size; uint32_t crc0, crc1, crc2, crc3; uint64_t t0, t1, t2; + uint16_t d16; + uint32_t d32; + uint64_t d64; // k0=CRC(x^(3*SEGMENTBYTES*8)), k1=CRC(x^(2*SEGMENTBYTES*8)), // k2=CRC(x^(SEGMENTBYTES*8)) @@ -88,7 +92,8 @@ uint32_t ExtendArm64(uint32_t crc, const uint8_t *data, size_t size) { t2 = (uint64_t)vmull_p64(crc2, k2); t1 = (uint64_t)vmull_p64(crc1, k1); t0 = (uint64_t)vmull_p64(crc0, k0); - crc = __crc32cd(crc3, *(uint64_t *)data); + std::memcpy(&d64, data, sizeof(d64)); + crc = __crc32cd(crc3, d64); data += sizeof(uint64_t); crc ^= __crc32cd(0, t2); crc ^= __crc32cd(0, t1); @@ -98,18 +103,21 @@ uint32_t ExtendArm64(uint32_t crc, const uint8_t *data, size_t size) { } while (length >= 8) { - crc = __crc32cd(crc, *(uint64_t *)data); + std::memcpy(&d64, data, sizeof(d64)); + crc = __crc32cd(crc, d64); data += 8; length -= 8; } if (length & 4) { - crc = __crc32cw(crc, *(uint32_t *)data); + std::memcpy(&d32, data, sizeof(d32)); + crc = __crc32cw(crc, d32); data += 4; } if (length & 2) { - crc = __crc32ch(crc, *(uint16_t *)data); + std::memcpy(&d16, data, sizeof(d16)); + crc = __crc32ch(crc, d16); data += 2; } diff --git a/src/i2p.cpp b/src/i2p.cpp index 1175366eb5d3..6713fdcea890 100644 --- a/src/i2p.cpp +++ b/src/i2p.cpp @@ -186,6 +186,7 @@ bool Session::Connect(const CService& to, Connection& conn, bool& proxy_error) // Refuse connecting to arbitrary ports. We don't specify any destination port to the SAM proxy // when connecting (SAM 3.1 does not use ports) and it forces/defaults it to I2P_SAM31_PORT. if (to.GetPort() != I2P_SAM31_PORT) { + Log("Error connecting to %s, connection refused due to arbitrary port %s", to.ToStringAddrPort(), to.GetPort()); proxy_error = false; return false; } diff --git a/src/test/README.md b/src/test/README.md index cf76f12007c1..2f69c24f86bc 100644 --- a/src/test/README.md +++ b/src/test/README.md @@ -15,7 +15,8 @@ that runs all of the unit tests. The main source file for the test library is fo Unit tests will be automatically compiled if dependencies were met in `./configure` and tests weren't explicitly disabled. -After configuring, they can be run with `make check`. +After configuring, they can be run with `make check`, which includes unit tests from +subtrees, or `make && make -C src check-unit` for just the unit tests. To run the unit tests manually, launch `src/test/test_dash`. To recompile after a test file was modified, run `make` and then run the test again. If you diff --git a/src/test/fuzz/net_permissions.cpp b/src/test/fuzz/net_permissions.cpp index 6ea79464d019..1e078b93854a 100644 --- a/src/test/fuzz/net_permissions.cpp +++ b/src/test/fuzz/net_permissions.cpp @@ -16,7 +16,7 @@ FUZZ_TARGET(net_permissions) { FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size()); - const std::string s = fuzzed_data_provider.ConsumeRandomLengthString(32); + const std::string s = fuzzed_data_provider.ConsumeRandomLengthString(1000); const NetPermissionFlags net_permission_flags = ConsumeWeakEnum(fuzzed_data_provider, ALL_NET_PERMISSION_FLAGS); NetWhitebindPermissions net_whitebind_permissions; diff --git a/src/test/fuzz/p2p_transport_serialization.cpp b/src/test/fuzz/p2p_transport_serialization.cpp index 530ce8524d8d..f5f8486e5f3f 100644 --- a/src/test/fuzz/p2p_transport_serialization.cpp +++ b/src/test/fuzz/p2p_transport_serialization.cpp @@ -349,6 +349,7 @@ std::unique_ptr MakeV2Transport(NodeId nodeid, bool initiator, RNG& r } else { // If it's longer, generate it from the RNG. This avoids having large amounts of // (hopefully) irrelevant data needing to be stored in the fuzzer data. + garb.resize(garb_len); for (auto& v : garb) v = uint8_t(rng()); } // Retrieve entropy diff --git a/src/test/fuzz/util.cpp b/src/test/fuzz/util.cpp index 3cfa9467fb9f..fb2f9c05fe9b 100644 --- a/src/test/fuzz/util.cpp +++ b/src/test/fuzz/util.cpp @@ -438,7 +438,7 @@ FILE* FuzzedFileProvider::open() [&] { mode = "a+"; }); -#if defined _GNU_SOURCE && !defined __ANDROID__ +#if defined _GNU_SOURCE && (defined(__linux__) || defined(__FreeBSD__)) const cookie_io_functions_t io_hooks = { FuzzedFileProvider::read, FuzzedFileProvider::write, diff --git a/src/util/strencodings.cpp b/src/util/strencodings.cpp index 95050042fb3a..4fea3925fd0e 100644 --- a/src/util/strencodings.cpp +++ b/src/util/strencodings.cpp @@ -476,6 +476,7 @@ bool ParseFixedPoint(const std::string &val, int decimals, int64_t *amount_out) std::string ToLower(const std::string& str) { std::string r; + r.reserve(str.size()); for (auto ch : str) r += ToLower(ch); return r; } @@ -483,6 +484,7 @@ std::string ToLower(const std::string& str) std::string ToUpper(const std::string& str) { std::string r; + r.reserve(str.size()); for (auto ch : str) r += ToUpper(ch); return r; } diff --git a/test/functional/feature_utxo_set_hash.py b/test/functional/feature_utxo_set_hash.py index 5f36f5dc9817..450e55ed348d 100755 --- a/test/functional/feature_utxo_set_hash.py +++ b/test/functional/feature_utxo_set_hash.py @@ -4,8 +4,6 @@ # file COPYING or http://www.opensource.org/licenses/mit-license.php. """Test UTXO set hash value calculation in gettxoutsetinfo.""" -import struct - from test_framework.messages import ( CBlock, COutPoint, @@ -58,7 +56,7 @@ def test_muhash_implementation(self): continue data = COutPoint(int(tx.rehash(), 16), n).serialize() - data += struct.pack("