refactor: Use empty() over eof() in the streams interface
What changed, and why it matters
This commit is a straightforward code cleanup: it renames the stream check from eof() (end-of-file) to empty() because the streams actually wrap in-memory buffers, not files. The behavior is identical, so there is no security issue here.
No action needed; this is a non-security refactoring change.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit refactors the stream interface in Bitcoin Core by replacing eof() with empty(). In DataStream and related classes, eof() was simply defined as size() == 0, and empty() is the equivalent replacement. The change affects seed parsing, a test serializer, and wallet database loading, but the logic remains the same. No functional or security-relevant change is introduced.
Changed components
src/net.cppsrc/serialize.hsrc/streams.hsrc/test/dbwrapper_tests.cppsrc/wallet/walletdb.cppInspect captured patch +4 / −5
diff --git a/src/net.cpp b/src/net.cpp
index 16591461..3ed7fd27 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -202,7 +202,7 @@ static std::vector<CAddress> ConvertSeeds(const std::vector<uint8_t> &vSeedsIn)
std::vector<CAddress> 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 4da48a0b..21b3325f 100644
--- a/src/serialize.h
+++ b/src/serialize.h
@@ -1127,7 +1127,7 @@ public:
void write(std::span<const std::byte> src) { GetStream().write(src); }
void read(std::span<std::byte> 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 466084e9..e5a18c56 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<value_type> dst)
diff --git a/src/test/dbwrapper_tests.cpp b/src/test/dbwrapper_tests.cpp
index 53cd0046..d3a9e543 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 617b8282..637cf4c5 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)) {
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.