refactor: Use fixed size ints over (un)signed ints for serialized values
What changed, and why it matters
This commit is a pure code cleanup: it replaces plain 'int' and 'unsigned int' type names with explicitly fixed-width 'int32_t' and 'uint32_t' in a few data structures. The project already assumed these sizes elsewhere, and the serialization format does not change, so there is no security or behavior impact.
No action required; this is a non-functional refactor.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch changes FlatFilePos, CDiskTxPos, and CBlockFileInfo to use int32_t/uint32_t instead of (unsigned) int. Bitcoin Core’s assumptions header already treats int as 32-bit and unsigned int as 32-bit, and all affected fields are serialized with fixed-size VARINT encoding. The constructor initializer syntax is also modernized. No functional or wire-format change is introduced.
Changed components
src/flatfile.hsrc/index/disktxpos.hsrc/node/blockstorage.hInspect captured patch +14 / −14
diff --git a/src/flatfile.h b/src/flatfile.h
index 3edb0b85..3ec4eaf3 100644
--- a/src/flatfile.h
+++ b/src/flatfile.h
@@ -13,16 +13,16 @@
struct FlatFilePos
{
- int nFile{-1};
- unsigned int nPos{0};
+ int32_t nFile{-1};
+ uint32_t nPos{0};
SERIALIZE_METHODS(FlatFilePos, obj) { READWRITE(VARINT_MODE(obj.nFile, VarIntMode::NONNEGATIVE_SIGNED), VARINT(obj.nPos)); }
FlatFilePos() = default;
- FlatFilePos(int nFileIn, unsigned int nPosIn) :
- nFile(nFileIn),
- nPos(nPosIn)
+ FlatFilePos(int32_t nFileIn, uint32_t nPosIn)
+ : nFile{nFileIn},
+ nPos{nPosIn}
{}
friend bool operator==(const FlatFilePos &a, const FlatFilePos &b) {
diff --git a/src/index/disktxpos.h b/src/index/disktxpos.h
index a0363846..5e4352db 100644
--- a/src/index/disktxpos.h
+++ b/src/index/disktxpos.h
@@ -10,14 +10,14 @@
struct CDiskTxPos : public FlatFilePos
{
- unsigned int nTxOffset{0}; // after header
+ uint32_t nTxOffset{0}; // after header
SERIALIZE_METHODS(CDiskTxPos, obj)
{
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;
diff --git a/src/node/blockstorage.h b/src/node/blockstorage.h
index e4d208c1..b397fc26 100644
--- a/src/node/blockstorage.h
+++ b/src/node/blockstorage.h
@@ -50,13 +50,13 @@ namespace kernel {
class CBlockFileInfo
{
public:
- unsigned int nBlocks{}; //!< number of blocks stored in file
- unsigned int nSize{}; //!< number of used bytes of block file
- unsigned int nUndoSize{}; //!< number of used bytes in the undo file
- unsigned int nHeightFirst{}; //!< lowest height of block in file
- unsigned int nHeightLast{}; //!< highest height of block in file
- uint64_t nTimeFirst{}; //!< earliest time of block in file
- uint64_t nTimeLast{}; //!< latest time of block in file
+ uint32_t nBlocks{}; //!< number of blocks stored in file
+ uint32_t nSize{}; //!< number of used bytes of block file
+ uint32_t nUndoSize{}; //!< number of used bytes in the undo file
+ uint32_t nHeightFirst{}; //!< lowest 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 nTimeLast{}; //!< latest time of block in file
SERIALIZE_METHODS(CBlockFileInfo, obj)
{
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.