Skip to content

Commit 34551cb

Browse files
committed
Merge bitcoin/bitcoin#27289: Refactor: Remove unused FlatFilePos::SetNull
fa67b81 Refactor: Remove unused FlatFilePos::SetNull (MarcoFalke) Pull request description: This is unused outside of tests and the default constructor. With C++11, it can be replaced by C++11 member initializers in the default constructor. Beside removing unused code, this also makes it less fragile in light of uninitialized memory. (See also bitcoin/bitcoin#26296 (comment)) If new code needs to set this to null, it can use `std::optional`, or in the worst case re-introduce this method. ACKs for top commit: dergoegge: Code review ACK fa67b81 TheCharlatan: ACK fa67b81 john-moffett: ACK fa67b81 Tree-SHA512: 465c5e3eb4625405c445695d33e09a1fc5185c7dd1e766ba06034fb093880bfc65441d5334f7d9b20e2e417c2075557d86059f59d9648ca0e62a54c699c029b9
2 parents 664500f + fa67b81 commit 34551cb

File tree

4 files changed

+8
-16
lines changed

4 files changed

+8
-16
lines changed

src/flatfile.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313

1414
struct FlatFilePos
1515
{
16-
int nFile;
17-
unsigned int nPos;
16+
int nFile{-1};
17+
unsigned int nPos{0};
1818

1919
SERIALIZE_METHODS(FlatFilePos, obj) { READWRITE(VARINT_MODE(obj.nFile, VarIntMode::NONNEGATIVE_SIGNED), VARINT(obj.nPos)); }
2020

21-
FlatFilePos() : nFile(-1), nPos(0) {}
21+
FlatFilePos() {}
2222

2323
FlatFilePos(int nFileIn, unsigned int nPosIn) :
2424
nFile(nFileIn),
@@ -33,7 +33,6 @@ struct FlatFilePos
3333
return !(a == b);
3434
}
3535

36-
void SetNull() { nFile = -1; nPos = 0; }
3736
bool IsNull() const { return (nFile == -1); }
3837

3938
std::string ToString() const;

src/index/disktxpos.h

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
struct CDiskTxPos : public FlatFilePos
1212
{
13-
unsigned int nTxOffset; // after header
13+
unsigned int nTxOffset{0}; // after header
1414

1515
SERIALIZE_METHODS(CDiskTxPos, obj)
1616
{
@@ -21,15 +21,7 @@ struct CDiskTxPos : public FlatFilePos
2121
CDiskTxPos(const FlatFilePos &blockIn, unsigned int nTxOffsetIn) : FlatFilePos(blockIn.nFile, blockIn.nPos), nTxOffset(nTxOffsetIn) {
2222
}
2323

24-
CDiskTxPos() {
25-
SetNull();
26-
}
27-
28-
void SetNull() {
29-
FlatFilePos::SetNull();
30-
nTxOffset = 0;
31-
}
24+
CDiskTxPos() {}
3225
};
3326

34-
3527
#endif // BITCOIN_INDEX_DISKTXPOS_H

src/test/flatfile_tests.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ BOOST_AUTO_TEST_CASE(flatfile_filename)
2323

2424
FlatFileSeq seq2(data_dir / "a", "b", 16 * 1024);
2525
BOOST_CHECK_EQUAL(seq2.FileName(pos), data_dir / "a" / "b00456.dat");
26+
27+
// Check default constructor IsNull
28+
assert(FlatFilePos{}.IsNull());
2629
}
2730

2831
BOOST_AUTO_TEST_CASE(flatfile_open)

src/test/fuzz/flatfile.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,4 @@ FUZZ_TARGET(flatfile)
2525
assert((*flat_file_pos == *another_flat_file_pos) != (*flat_file_pos != *another_flat_file_pos));
2626
}
2727
(void)flat_file_pos->ToString();
28-
flat_file_pos->SetNull();
29-
assert(flat_file_pos->IsNull());
3028
}

0 commit comments

Comments
 (0)