refactor: Use fixed size ints over (un)signed ints for serialized values

Bitcoin Core already assumes that 'unsigned int' means uint32_t and
'signed int' means int32_t. See src/compat/assumptions.h. Also, any
serialized integral value must be of a fixed size.

So make the fixed size explicit in this documenting refactor, which does
not change the behavior on any platform.
This commit is contained in:
MarcoFalke committed 2025-10-30 17:51:38 +01:00
1 parent fa01f38e53
commit fa4f388fc9
3 files changed
+14 -14

No files matched your search

+5 -5
View File
@@ -13,16 +13,16 @@
struct FlatFilePos struct FlatFilePos
{ {
int nFile{-1}; int32_t nFile{-1};
unsigned int nPos{0}; uint32_t nPos{0};
SERIALIZE_METHODS(FlatFilePos, obj) { READWRITE(VARINT_MODE(obj.nFile, VarIntMode::NONNEGATIVE_SIGNED), VARINT(obj.nPos)); } SERIALIZE_METHODS(FlatFilePos, obj) { READWRITE(VARINT_MODE(obj.nFile, VarIntMode::NONNEGATIVE_SIGNED), VARINT(obj.nPos)); }
FlatFilePos() = default; FlatFilePos() = default;
FlatFilePos(int nFileIn, unsigned int nPosIn) : FlatFilePos(int32_t nFileIn, uint32_t nPosIn)
nFile(nFileIn), : nFile{nFileIn},
nPos(nPosIn) nPos{nPosIn}
{} {}
friend bool operator==(const FlatFilePos &a, const FlatFilePos &b) { friend bool operator==(const FlatFilePos &a, const FlatFilePos &b) {
+2 -2
View File
@@ -10,14 +10,14 @@
struct CDiskTxPos : public FlatFilePos struct CDiskTxPos : public FlatFilePos
{ {
unsigned int nTxOffset{0}; // after header uint32_t nTxOffset{0}; // after header
SERIALIZE_METHODS(CDiskTxPos, obj) SERIALIZE_METHODS(CDiskTxPos, obj)
{ {
READWRITE(AsBase<FlatFilePos>(obj), VARINT(obj.nTxOffset)); READWRITE(AsBase<FlatFilePos>(obj), VARINT(obj.nTxOffset));
} }
CDiskTxPos(const FlatFilePos &blockIn, unsigned int nTxOffsetIn) : FlatFilePos(blockIn.nFile, blockIn.nPos), nTxOffset(nTxOffsetIn) { CDiskTxPos(const FlatFilePos& blockIn, uint32_t nTxOffsetIn) : FlatFilePos{blockIn.nFile, blockIn.nPos}, nTxOffset{nTxOffsetIn} {
} }
CDiskTxPos() = default; CDiskTxPos() = default;
+7 -7
View File
@@ -50,13 +50,13 @@ namespace kernel {
class CBlockFileInfo class CBlockFileInfo
{ {
public: public:
unsigned int nBlocks{}; //!< number of blocks stored in file uint32_t nBlocks{}; //!< number of blocks stored in file
unsigned int nSize{}; //!< number of used bytes of block file uint32_t nSize{}; //!< number of used bytes of block file
unsigned int nUndoSize{}; //!< number of used bytes in the undo file uint32_t nUndoSize{}; //!< number of used bytes in the undo file
unsigned int nHeightFirst{}; //!< lowest height of block in file uint32_t nHeightFirst{}; //!< lowest height of block in file
unsigned int nHeightLast{}; //!< highest height of block in file uint32_t nHeightLast{}; //!< highest height of block in file
uint64_t nTimeFirst{}; //!< earliest time of block in file uint64_t nTimeFirst{}; //!< earliest time of block in file
uint64_t nTimeLast{}; //!< latest time of block in file uint64_t nTimeLast{}; //!< latest time of block in file
SERIALIZE_METHODS(CBlockFileInfo, obj) SERIALIZE_METHODS(CBlockFileInfo, obj)
{ {