diff --git a/src/flatfile.h b/src/flatfile.h index 009984f6b857f2..9c0a1541eabf4e 100644 --- a/src/flatfile.h +++ b/src/flatfile.h @@ -13,15 +13,15 @@ struct FlatFilePos { - int nFile; - unsigned int nPos; + int nFile{-1}; + unsigned int nPos{0}; SERIALIZE_METHODS(FlatFilePos, obj) { READWRITE(VARINT_MODE(obj.nFile, VarIntMode::NONNEGATIVE_SIGNED), VARINT(obj.nPos)); } - FlatFilePos() : nFile(-1), nPos(0) {} + FlatFilePos() {} FlatFilePos(int nFileIn, unsigned int nPosIn) : nFile(nFileIn), @@ -36,7 +36,6 @@ struct FlatFilePos return !(a == b); } - void SetNull() { nFile = -1; nPos = 0; } bool IsNull() const { return (nFile == -1); } std::string ToString() const; diff --git a/src/index/disktxpos.h b/src/index/disktxpos.h index 3166053226b2ec..7718755b7899a1 100644 --- a/src/index/disktxpos.h +++ b/src/index/disktxpos.h @@ -10,7 +10,7 @@ struct CDiskTxPos : public FlatFilePos { - unsigned int nTxOffset; // after header + unsigned int nTxOffset{0}; // after header SERIALIZE_METHODS(CDiskTxPos, obj) { @@ -21,15 +21,7 @@ struct CDiskTxPos : public FlatFilePos CDiskTxPos(const FlatFilePos &blockIn, unsigned int nTxOffsetIn) : FlatFilePos(blockIn.nFile, blockIn.nPos), nTxOffset(nTxOffsetIn) { } - CDiskTxPos() { - SetNull(); - } - - void SetNull() { - FlatFilePos::SetNull(); - nTxOffset = 0; - } + CDiskTxPos() {} }; - #endif // BITCOIN_INDEX_DISKTXPOS_H diff --git a/src/test/flatfile_tests.cpp b/src/test/flatfile_tests.cpp index f4bc320f3c6374..09b94e78fbc6c7 100644 --- a/src/test/flatfile_tests.cpp +++ b/src/test/flatfile_tests.cpp @@ -23,6 +23,9 @@ BOOST_AUTO_TEST_CASE(flatfile_filename) FlatFileSeq seq2(data_dir / "a", "b", 16 * 1024); BOOST_CHECK_EQUAL(seq2.FileName(pos), data_dir / "a" / "b00456.dat"); + + // Check default constructor IsNull + assert(FlatFilePos{}.IsNull()); } BOOST_AUTO_TEST_CASE(flatfile_open) diff --git a/src/test/fuzz/flatfile.cpp b/src/test/fuzz/flatfile.cpp index d142e374b1caec..b5c82c14b4c0e5 100644 --- a/src/test/fuzz/flatfile.cpp +++ b/src/test/fuzz/flatfile.cpp @@ -25,6 +25,4 @@ FUZZ_TARGET(flatfile) assert((*flat_file_pos == *another_flat_file_pos) != (*flat_file_pos != *another_flat_file_pos)); } (void)flat_file_pos->ToString(); - flat_file_pos->SetNull(); - assert(flat_file_pos->IsNull()); }