From fa20bc2ec27522959cdf1ad35d54f080aafbfc47 Mon Sep 17 00:00:00 2001 From: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz> Date: Mon, 2 Feb 2026 17:56:13 +0100 Subject: [PATCH] refactor: Use empty() over eof() in the streams interface End-of-file does not really make sense for streams that wrap buffers. So replace it by the equivalent empty() checks. --- src/net.cpp | 2 +- src/serialize.h | 2 +- src/streams.h | 1 - src/test/dbwrapper_tests.cpp | 2 +- src/wallet/walletdb.cpp | 2 +- 5 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/net.cpp b/src/net.cpp index 16591461efb..3ed7fd2778e 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -202,7 +202,7 @@ static std::vector ConvertSeeds(const std::vector &vSeedsIn) std::vector vSeedsOut; FastRandomContext rng; ParamsStream s{DataStream{vSeedsIn}, CAddress::V2_NETWORK}; - while (!s.eof()) { + while (!s.empty()) { CService endpoint; s >> endpoint; CAddress addr{endpoint, SeedsServiceFlags()}; diff --git a/src/serialize.h b/src/serialize.h index 4da48a0bb31..21b3325f7a7 100644 --- a/src/serialize.h +++ b/src/serialize.h @@ -1127,7 +1127,7 @@ public: void write(std::span src) { GetStream().write(src); } void read(std::span dst) { GetStream().read(dst); } void ignore(size_t num) { GetStream().ignore(num); } - bool eof() const { return GetStream().eof(); } + bool empty() const { return GetStream().empty(); } size_t size() const { return GetStream().size(); } //! Get reference to stream parameters. diff --git a/src/streams.h b/src/streams.h index 466084e9fa0..e5a18c56b74 100644 --- a/src/streams.h +++ b/src/streams.h @@ -195,7 +195,6 @@ public: // // Stream subset // - bool eof() const { return size() == 0; } int in_avail() const { return size(); } void read(std::span dst) diff --git a/src/test/dbwrapper_tests.cpp b/src/test/dbwrapper_tests.cpp index 53cd0046c3a..d3a9e54348b 100644 --- a/src/test/dbwrapper_tests.cpp +++ b/src/test/dbwrapper_tests.cpp @@ -364,7 +364,7 @@ struct StringContentsSerializer { { str.clear(); uint8_t c{0}; - while (!s.eof()) { + while (!s.empty()) { s >> c; str.push_back(c); } diff --git a/src/wallet/walletdb.cpp b/src/wallet/walletdb.cpp index 617b8282d9d..637cf4c57b7 100644 --- a/src/wallet/walletdb.cpp +++ b/src/wallet/walletdb.cpp @@ -377,7 +377,7 @@ bool LoadCryptedKey(CWallet* pwallet, DataStream& ssKey, DataStream& ssValue, st // Get the checksum and check it bool checksum_valid = false; - if (!ssValue.eof()) { + if (!ssValue.empty()) { uint256 checksum; ssValue >> checksum; if (!(checksum_valid = Hash(vchPrivKey) == checksum)) {