Skip to content

backport: trivial 2025 05 08 #6668

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ task:
<< : *GLOBAL_TASK_TEMPLATE
macos_instance:
# Use latest image, but hardcode version to avoid silent upgrades (and breaks)
image: monterey-xcode-13.2 # https://cirrus-ci.org/guide/macOS
image: monterey-xcode-13.3 # https://cirrus-ci.org/guide/macOS
env:
DANGER_RUN_CI_ON_HOST: "true"
CI_USE_APT_INSTALL: "no"
Expand Down
97 changes: 54 additions & 43 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -513,19 +513,22 @@ AX_CHECK_COMPILE_FLAG([-Wsuggest-override], [WARN_CXXFLAGS="$WARN_CXXFLAGS -Wsug
AX_CHECK_COMPILE_FLAG([-Wimplicit-fallthrough], [WARN_CXXFLAGS="$WARN_CXXFLAGS -Wimplicit-fallthrough"], [], [$CXXFLAG_WERROR])
AX_CHECK_COMPILE_FLAG([-Wunreachable-code], [WARN_CXXFLAGS="$WARN_CXXFLAGS -Wunreachable-code"], [], [$CXXFLAG_WERROR])
AX_CHECK_COMPILE_FLAG([-Wdocumentation], [WARN_CXXFLAGS="$WARN_CXXFLAGS -Wdocumentation"], [], [$CXXFLAG_WERROR])
AX_CHECK_COMPILE_FLAG([-Wself-assign], [WARN_CXXFLAGS="$WARN_CXXFLAGS -Wself-assign"], [], [$CXXFLAG_WERROR])

dnl Some compilers (gcc) ignore unknown -Wno-* options, but warn about all
dnl unknown options if any other warning is produced. Test the -Wfoo case, and
dnl set the -Wno-foo case if it works.
AX_CHECK_COMPILE_FLAG([-Wunused-parameter], [NOWARN_CXXFLAGS="$NOWARN_CXXFLAGS -Wno-unused-parameter"], [], [$CXXFLAG_WERROR])
AX_CHECK_COMPILE_FLAG([-Wself-assign], [NOWARN_CXXFLAGS="$NOWARN_CXXFLAGS -Wno-self-assign"], [], [$CXXFLAG_WERROR])
if test "$suppress_external_warnings" != "yes" ; then
AX_CHECK_COMPILE_FLAG([-Wdeprecated-copy], [NOWARN_CXXFLAGS="$NOWARN_CXXFLAGS -Wno-deprecated-copy"], [], [$CXXFLAG_WERROR])
fi

dnl Don't allow extended (non-ASCII) symbols in identifiers. This is easier for code review.
AX_CHECK_COMPILE_FLAG([-fno-extended-identifiers], [CORE_CXXFLAGS="$CORE_CXXFLAGS -fno-extended-identifiers"], [], [$CXXFLAG_WERROR])

dnl Currently all versions of gcc are subject to a class of bugs, see the
dnl gccbug_90348 test case (only reproduces on GCC 11 and earlier) and
dnl https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111843. To work around that, set
dnl -fstack-reuse=none for all gcc builds. (Only gcc understands this flag)
AX_CHECK_COMPILE_FLAG([-fstack-reuse=none], [CORE_CXXFLAGS="$CORE_CXXFLAGS -fstack-reuse=none"])

enable_arm_crc=no
enable_arm_shani=no
enable_sse42=no
Expand Down Expand Up @@ -782,17 +785,23 @@ case $host in
dnl It's safe to add these paths even if the functionality is disabled by
dnl the user (--without-wallet or --without-gui for example).

dnl Homebrew may create symlinks in /usr/local/include for some packages.
dnl Because MacOS's clang internally adds "-I /usr/local/include" to its search
dnl paths, this will negate efforts to use -isystem for those packages, as they
dnl will be found first in /usr/local. Use the internal "-internal-isystem"
dnl option to system-ify all /usr/local/include paths without adding it to the list
dnl of search paths in case it's not already there.
if test "$suppress_external_warnings" != "no"; then
AX_CHECK_PREPROC_FLAG([-Xclang -internal-isystem/usr/local/include], [CORE_CPPFLAGS="$CORE_CPPFLAGS -Xclang -internal-isystem/usr/local/include"], [], [$CXXFLAG_WERROR])
fi

if test "$use_bdb" != "no" && $BREW list --versions berkeley-db@4 >/dev/null && test "$BDB_CFLAGS" = "" && test "$BDB_LIBS" = ""; then
bdb_prefix=$($BREW --prefix berkeley-db@4 2>/dev/null)
dnl This must precede the call to BITCOIN_FIND_BDB48 below.
BDB_CFLAGS="-I$bdb_prefix/include"
BDB_LIBS="-L$bdb_prefix/lib -ldb_cxx-4.8"
fi

if test "$use_sqlite" != "no" && $BREW list --versions sqlite3 >/dev/null; then
export PKG_CONFIG_PATH="$($BREW --prefix sqlite3 2>/dev/null)/lib/pkgconfig:$PKG_CONFIG_PATH"
fi

if $BREW list --versions qt@5 >/dev/null; then
export PKG_CONFIG_PATH="$($BREW --prefix qt@5 2>/dev/null)/lib/pkgconfig:$PKG_CONFIG_PATH"
fi
Expand All @@ -812,20 +821,20 @@ case $host in
if test "$use_upnp" != "no" && $BREW list --versions miniupnpc >/dev/null; then
miniupnpc_prefix=$($BREW --prefix miniupnpc 2>/dev/null)
if test "$suppress_external_warnings" != "no"; then
CORE_CPPFLAGS="$CORE_CPPFLAGS -isystem $miniupnpc_prefix/include"
MINIUPNPC_CPPFLAGS="-isystem $miniupnpc_prefix/include"
else
CORE_CPPFLAGS="$CORE_CPPFLAGS -I$miniupnpc_prefix/include"
MINIUPNPC_CPPFLAGS="-I$miniupnpc_prefix/include"
fi
CORE_LDFLAGS="$CORE_LDFLAGS -L$miniupnpc_prefix/lib"
MINIUPNPC_LIBS="-L$miniupnpc_prefix/lib"
fi
if test "$use_natpmp" != "no" && $BREW list --versions libnatpmp >/dev/null; then
libnatpmp_prefix=$($BREW --prefix libnatpmp 2>/dev/null)
if test "$suppress_external_warnings" != "no"; then
CORE_CPPFLAGS="$CORE_CPPFLAGS -isystem $libnatpmp_prefix/include"
NATPMP_CPPFLAGS="-isystem $libnatpmp_prefix/include"
else
CORE_CPPFLAGS="$CORE_CPPFLAGS -I$libnatpmp_prefix/include"
NATPMP_CPPFLAGS="-I$libnatpmp_prefix/include"
fi
CORE_LDFLAGS="$CORE_LDFLAGS -L$libnatpmp_prefix/lib"
NATPMP_LIBS="-L$libnatpmp_prefix/lib"
fi
;;
esac
Expand Down Expand Up @@ -981,11 +990,6 @@ if test "$TARGET_OS" != "windows"; then
AX_CHECK_COMPILE_FLAG([-fPIC], [PIC_FLAGS="-fPIC"])
fi

dnl Currently all versions of gcc are subject to a class of bugs, see the
dnl gccbug_90348 test case (only reproduces on GCC 11 and earlier) and the related bugs of
dnl https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90348. To work around that, set
dnl -fstack-reuse=none for all gcc builds. (Only gcc understands this flag)
AX_CHECK_COMPILE_FLAG([-fstack-reuse=none], [HARDENED_CXXFLAGS="$HARDENED_CXXFLAGS -fstack-reuse=none"])
if test "$use_hardening" != "no"; then
use_hardening=yes
AX_CHECK_COMPILE_FLAG([-Wstack-protector], [HARDENED_CXXFLAGS="$HARDENED_CXXFLAGS -Wstack-protector"])
Expand Down Expand Up @@ -1418,38 +1422,44 @@ AM_CONDITIONAL([ENABLE_USDT_TRACEPOINTS], [test "$use_usdt" = "yes"])

dnl Check for libminiupnpc (optional)
if test "$use_upnp" != "no"; then
TEMP_CPPFLAGS="$CPPFLAGS"
CPPFLAGS="$CPPFLAGS $MINIUPNPC_CPPFLAGS"
AC_CHECK_HEADERS(
[miniupnpc/miniupnpc.h miniupnpc/upnpcommands.h miniupnpc/upnperrors.h],
[AC_CHECK_LIB([miniupnpc], [upnpDiscover], [MINIUPNPC_LIBS=-lminiupnpc], [have_miniupnpc=no])],
[AC_CHECK_LIB([miniupnpc], [upnpDiscover], [MINIUPNPC_LIBS="$MINIUPNPC_LIBS -lminiupnpc"], [have_miniupnpc=no], [$MINIUPNPC_LIBS])],
[have_miniupnpc=no]
)
dnl The minimum supported miniUPnPc API version is set to 10. This keeps compatibility
dnl with Ubuntu 16.04 LTS and Debian 8 libminiupnpc-dev packages.
if test "$have_miniupnpc" != "no"; then
AC_MSG_CHECKING([whether miniUPnPc API version is supported])
AC_PREPROC_IFELSE([AC_LANG_PROGRAM([[
@%:@include <miniupnpc/miniupnpc.h>
]], [[
#if MINIUPNPC_API_VERSION >= 10
// Everything is okay
#else
# error miniUPnPc API version is too old
#endif
]])],[
AC_MSG_RESULT([yes])
],[
AC_MSG_RESULT([no])
AC_MSG_WARN([miniUPnPc API version < 10 is unsupported, disabling UPnP support.])
have_miniupnpc=no
])
fi
dnl The minimum supported miniUPnPc API version is set to 10. This keeps compatibility
dnl with Ubuntu 16.04 LTS and Debian 8 libminiupnpc-dev packages.
if test "$have_miniupnpc" != "no"; then
AC_MSG_CHECKING([whether miniUPnPc API version is supported])
AC_PREPROC_IFELSE([AC_LANG_PROGRAM([[
@%:@include <miniupnpc/miniupnpc.h>
]], [[
#if MINIUPNPC_API_VERSION >= 10
// Everything is okay
#else
# error miniUPnPc API version is too old
#endif
]])],[
AC_MSG_RESULT([yes])
],[
AC_MSG_RESULT([no])
AC_MSG_WARN([miniUPnPc API version < 10 is unsupported, disabling UPnP support.])
have_miniupnpc=no
])
fi
CPPFLAGS="$TEMP_CPPFLAGS"
fi

dnl Check for libnatpmp (optional).
if test "$use_natpmp" != "no"; then
TEMP_CPPFLAGS="$CPPFLAGS"
CPPFLAGS="$CPPFLAGS $NATPMP_CPPFLAGS"
AC_CHECK_HEADERS([natpmp.h],
[AC_CHECK_LIB([natpmp], [initnatpmp], [NATPMP_LIBS=-lnatpmp], [have_natpmp=no])],
[AC_CHECK_LIB([natpmp], [initnatpmp], [NATPMP_LIBS="$NATPMP_LIBS -lnatpmp"], [have_natpmp=no], [$NATPMP_LIBS])],
[have_natpmp=no])
CPPFLAGS="$TEMP_CPPFLAGS"
fi

if test "$build_bitcoin_wallet$build_bitcoin_cli$build_bitcoin_tx$build_bitcoind$bitcoin_enable_qt$use_tests$use_bench" = "nonononononono"; then
Expand Down Expand Up @@ -1508,6 +1518,7 @@ fi

dnl libevent check

use_libevent=no
if test "$build_bitcoin_cli$build_bitcoind$bitcoin_enable_qt$use_tests$use_bench" != "nonononono"; then
PKG_CHECK_MODULES([EVENT], [libevent >= 2.0.21], [use_libevent=yes], [AC_MSG_ERROR([libevent version 2.0.21 or greater not found.])])
if test "$TARGET_OS" != "windows"; then
Expand Down Expand Up @@ -1681,7 +1692,7 @@ else
use_upnp=yes
AC_DEFINE([USE_UPNP], [1], [Define to 1 if UPnP support should be compiled in.])
if test "$TARGET_OS" = "windows"; then
MINIUPNPC_CPPFLAGS="-DSTATICLIB -DMINIUPNP_STATICLIB"
MINIUPNPC_CPPFLAGS="$MINIUPNPC_CPPFLAGS -DMINIUPNP_STATICLIB"
fi
else
AC_MSG_RESULT([no])
Expand All @@ -1702,7 +1713,7 @@ else
use_natpmp=yes
AC_DEFINE([USE_NATPMP], [1], [Define to 1 if UPnP support should be compiled in.])
if test "$TARGET_OS" = "windows"; then
NATPMP_CPPFLAGS="-DSTATICLIB -DNATPMP_STATICLIB"
NATPMP_CPPFLAGS="$NATPMP_CPPFLAGS -DSTATICLIB -DNATPMP_STATICLIB"
fi
else
AC_MSG_RESULT([no])
Expand Down
6 changes: 1 addition & 5 deletions src/netbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -639,10 +639,7 @@ std::unique_ptr<Sock> ConnectDirectly(const CService& dest, bool manual_connecti

std::unique_ptr<Sock> Proxy::Connect() const
{
if (!IsValid()) {
LogPrintf("Cannot connect to invalid Proxy\n");
return {};
}
if (!IsValid()) return {};

if (!m_is_unix_socket) return ConnectDirectly(proxy, /*manual_connection=*/true);

Expand All @@ -663,7 +660,6 @@ std::unique_ptr<Sock> Proxy::Connect() const
socklen_t len = sizeof(addrun);

if(!ConnectToSocket(*sock, (struct sockaddr*)&addrun, len, path, /*manual_connection=*/true)) {
LogPrintf("Cannot connect to socket for %s\n", path);
return {};
}

Expand Down
33 changes: 7 additions & 26 deletions src/test/fuzz/addrman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,40 +271,21 @@ FUZZ_TARGET(addrman, .init = initialize_addrman)
[&] {
std::vector<CAddress> addresses;
LIMITED_WHILE(fuzzed_data_provider.ConsumeBool(), 10000) {
const std::optional<CAddress> opt_address = ConsumeDeserializable<CAddress>(fuzzed_data_provider);
if (!opt_address) {
break;
}
addresses.push_back(*opt_address);
}
const std::optional<CNetAddr> opt_net_addr = ConsumeDeserializable<CNetAddr>(fuzzed_data_provider);
if (opt_net_addr) {
addr_man.Add(addresses, *opt_net_addr, std::chrono::seconds{ConsumeTime(fuzzed_data_provider, 0, 100000000)});
addresses.push_back(ConsumeAddress(fuzzed_data_provider));
}
addr_man.Add(addresses, ConsumeNetAddr(fuzzed_data_provider), std::chrono::seconds{ConsumeTime(fuzzed_data_provider, 0, 100000000)});
},
[&] {
const std::optional<CService> opt_service = ConsumeDeserializable<CService>(fuzzed_data_provider);
if (opt_service) {
addr_man.Good(*opt_service, NodeSeconds{std::chrono::seconds{ConsumeTime(fuzzed_data_provider)}});
}
addr_man.Good(ConsumeService(fuzzed_data_provider), NodeSeconds{std::chrono::seconds{ConsumeTime(fuzzed_data_provider)}});
},
[&] {
const std::optional<CService> opt_service = ConsumeDeserializable<CService>(fuzzed_data_provider);
if (opt_service) {
addr_man.Attempt(*opt_service, fuzzed_data_provider.ConsumeBool(), NodeSeconds{std::chrono::seconds{ConsumeTime(fuzzed_data_provider)}});
}
addr_man.Attempt(ConsumeService(fuzzed_data_provider), fuzzed_data_provider.ConsumeBool(), NodeSeconds{std::chrono::seconds{ConsumeTime(fuzzed_data_provider)}});
},
[&] {
const std::optional<CService> opt_service = ConsumeDeserializable<CService>(fuzzed_data_provider);
if (opt_service) {
addr_man.Connected(*opt_service, NodeSeconds{std::chrono::seconds{ConsumeTime(fuzzed_data_provider)}});
}
addr_man.Connected(ConsumeService(fuzzed_data_provider), NodeSeconds{std::chrono::seconds{ConsumeTime(fuzzed_data_provider)}});
},
[&] {
const std::optional<CService> opt_service = ConsumeDeserializable<CService>(fuzzed_data_provider);
if (opt_service) {
addr_man.SetServices(*opt_service, ConsumeWeakEnum(fuzzed_data_provider, ALL_SERVICE_FLAGS));
}
addr_man.SetServices(ConsumeService(fuzzed_data_provider), ConsumeWeakEnum(fuzzed_data_provider, ALL_SERVICE_FLAGS));
});
}
(void)addr_man.Size();
Expand All @@ -328,4 +309,4 @@ FUZZ_TARGET(addrman_serdeser, .init = initialize_addrman)
data_stream << addr_man1;
data_stream >> addr_man2;
assert(addr_man1 == addr_man2);
}
}
10 changes: 9 additions & 1 deletion src/test/fuzz/connman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ FUZZ_TARGET(connman, .init = initialize_connman)
{
FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
SetMockTime(ConsumeTime(fuzzed_data_provider));
CConnman connman{fuzzed_data_provider.ConsumeIntegral<uint64_t>(),
ConnmanTestMsg connman{fuzzed_data_provider.ConsumeIntegral<uint64_t>(),
fuzzed_data_provider.ConsumeIntegral<uint64_t>(),
*g_setup->m_node.addrman,
*g_setup->m_node.netgroupman,
Expand All @@ -48,6 +48,12 @@ FUZZ_TARGET(connman, .init = initialize_connman)
CNode random_node = ConsumeNode(fuzzed_data_provider);
CSubNet random_subnet;
std::string random_string;

LIMITED_WHILE(fuzzed_data_provider.ConsumeBool(), 100) {
CNode& p2p_node{*ConsumeNodeAsUniquePtr(fuzzed_data_provider).release()};
connman.AddTestNode(p2p_node);
}

LIMITED_WHILE(fuzzed_data_provider.ConsumeBool(), 10000) {
CallOneOf(
fuzzed_data_provider,
Expand Down Expand Up @@ -138,4 +144,6 @@ FUZZ_TARGET(connman, .init = initialize_connman)
(void)connman.GetTotalBytesSent();
(void)connman.GetTryNewOutboundPeer();
(void)connman.GetUseAddrmanOutgoing();

connman.ClearTestNodes();
}
12 changes: 12 additions & 0 deletions src/test/fuzz/muhash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,19 @@ FUZZ_TARGET(muhash)
},
[&] {
// Test that dividing a MuHash by itself brings it back to it's initial state

// See note about clang + self-assignment in test/uint256_tests.cpp
#if defined(__clang__)
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wself-assign-overloaded"
#endif

muhash /= muhash;

#if defined(__clang__)
# pragma clang diagnostic pop
#endif

muhash.Finalize(out);
out2 = uint256S(initial_state_hash);
},
Expand Down
19 changes: 19 additions & 0 deletions src/test/uint256_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,22 @@ BOOST_AUTO_TEST_CASE( conversion )

BOOST_AUTO_TEST_CASE( operator_with_self )
{

/* Clang 16 and earlier detects v -= v and v /= v as self-assignments
to 0 and 1 respectively.
See: https://github.com/llvm/llvm-project/issues/42469
and the fix in commit c5302325b2a62d77cf13dd16cd5c19141862fed0 .

This makes some sense for arithmetic classes, but could be considered a bug
elsewhere. Disable the warning here so that the code can be tested, but the
warning should remain on as there will likely always be a better way to
express this.
*/

#if defined(__clang__)
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wself-assign-overloaded"
#endif
arith_uint256 v = UintToArith256(uint256S("02"));
v *= v;
BOOST_CHECK(v == UintToArith256(uint256S("04")));
Expand All @@ -277,6 +293,9 @@ BOOST_AUTO_TEST_CASE( operator_with_self )
BOOST_CHECK(v == UintToArith256(uint256S("02")));
v -= v;
BOOST_CHECK(v == UintToArith256(uint256S("0")));
#if defined(__clang__)
# pragma clang diagnostic pop
#endif
}

BOOST_AUTO_TEST_CASE( check_ONE )
Expand Down
26 changes: 16 additions & 10 deletions src/wallet/walletdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1160,21 +1160,27 @@ std::unique_ptr<WalletDatabase> MakeDatabase(const fs::path& path, const Databas

if (format == DatabaseFormat::SQLITE) {
#ifdef USE_SQLITE
return MakeSQLiteDatabase(path, options, status, error);
#else
error = Untranslated(strprintf("Failed to open database path '%s'. Build does not support SQLite database format.", fs::PathToString(path)));
status = DatabaseStatus::FAILED_BAD_FORMAT;
return nullptr;
if constexpr (true) {
return MakeSQLiteDatabase(path, options, status, error);
} else
#endif
{
error = Untranslated(strprintf("Failed to open database path '%s'. Build does not support SQLite database format.", fs::PathToString(path)));
status = DatabaseStatus::FAILED_BAD_FORMAT;
return nullptr;
}
}

#ifdef USE_BDB
return MakeBerkeleyDatabase(path, options, status, error);
#else
error = Untranslated(strprintf("Failed to open database path '%s'. Build does not support Berkeley DB database format.", fs::PathToString(path)));
status = DatabaseStatus::FAILED_BAD_FORMAT;
return nullptr;
if constexpr (true) {
return MakeBerkeleyDatabase(path, options, status, error);
} else
#endif
{
error = Untranslated(strprintf("Failed to open database path '%s'. Build does not support Berkeley DB database format.", fs::PathToString(path)));
status = DatabaseStatus::FAILED_BAD_FORMAT;
return nullptr;
}
Comment on lines +1163 to +1183
Copy link
Preview

Copilot AI May 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The use of 'if constexpr (true)' renders the else branch unreachable; consider refactoring this block to simplify the control flow and remove dead code.

Copilot uses AI. Check for mistakes.

}

/** Return object for accessing dummy database with no read/write capabilities. */
Expand Down
Loading
Loading