mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-12 11:19:08 -05:00
Merge #19818: p2p: change CInv::type
from int
to uint32_t
, fix UBSan warning
7984c39be1
test framework: serialize/deserialize inv type as unsigned int (Jon Atack)407175e0c2
p2p: change CInv::type from int to uint32_t (Jon Atack) Pull request description: Fixes UBSan implicit-integer-sign-change issue per https://github.com/bitcoin/bitcoin/pull/19610#issuecomment-680686460. Credit to Crypt-iQ for finding and reporting the issue and to vasild for the original review suggestion in https://github.com/bitcoin/bitcoin/pull/19590#pullrequestreview-455788826. Closes #19678. ACKs for top commit: laanwj: ACK7984c39be1
MarcoFalke: ACK7984c39be1
🌻 vasild: ACK7984c39be
Tree-SHA512: 59f3a75f40ce066ca6f0bb1927197254238302b4073af1574bdbfe6ed580876437be804be4e47d51467d604f0d9e3a5875159f7f2edbb2351fdb2bb9465100b5
This commit is contained in:
commit
bd60a9a8ed
3 changed files with 7 additions and 7 deletions
|
@ -163,7 +163,7 @@ CInv::CInv()
|
||||||
hash.SetNull();
|
hash.SetNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
CInv::CInv(int typeIn, const uint256& hashIn) : type(typeIn), hash(hashIn) {}
|
CInv::CInv(uint32_t typeIn, const uint256& hashIn) : type(typeIn), hash(hashIn) {}
|
||||||
|
|
||||||
bool operator<(const CInv& a, const CInv& b)
|
bool operator<(const CInv& a, const CInv& b)
|
||||||
{
|
{
|
||||||
|
|
|
@ -408,7 +408,7 @@ class CInv
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CInv();
|
CInv();
|
||||||
CInv(int typeIn, const uint256& hashIn);
|
CInv(uint32_t typeIn, const uint256& hashIn);
|
||||||
|
|
||||||
SERIALIZE_METHODS(CInv, obj) { READWRITE(obj.type, obj.hash); }
|
SERIALIZE_METHODS(CInv, obj) { READWRITE(obj.type, obj.hash); }
|
||||||
|
|
||||||
|
@ -435,7 +435,7 @@ public:
|
||||||
return type == MSG_BLOCK || type == MSG_FILTERED_BLOCK || type == MSG_CMPCT_BLOCK || type == MSG_WITNESS_BLOCK;
|
return type == MSG_BLOCK || type == MSG_FILTERED_BLOCK || type == MSG_CMPCT_BLOCK || type == MSG_WITNESS_BLOCK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int type;
|
uint32_t type;
|
||||||
uint256 hash;
|
uint256 hash;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -245,8 +245,8 @@ class CInv:
|
||||||
MSG_TX | MSG_WITNESS_FLAG: "WitnessTx",
|
MSG_TX | MSG_WITNESS_FLAG: "WitnessTx",
|
||||||
MSG_BLOCK | MSG_WITNESS_FLAG: "WitnessBlock",
|
MSG_BLOCK | MSG_WITNESS_FLAG: "WitnessBlock",
|
||||||
MSG_FILTERED_BLOCK: "filtered Block",
|
MSG_FILTERED_BLOCK: "filtered Block",
|
||||||
4: "CompactBlock",
|
MSG_CMPCT_BLOCK: "CompactBlock",
|
||||||
5: "WTX",
|
MSG_WTX: "WTX",
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, t=0, h=0):
|
def __init__(self, t=0, h=0):
|
||||||
|
@ -254,12 +254,12 @@ class CInv:
|
||||||
self.hash = h
|
self.hash = h
|
||||||
|
|
||||||
def deserialize(self, f):
|
def deserialize(self, f):
|
||||||
self.type = struct.unpack("<i", f.read(4))[0]
|
self.type = struct.unpack("<I", f.read(4))[0]
|
||||||
self.hash = deser_uint256(f)
|
self.hash = deser_uint256(f)
|
||||||
|
|
||||||
def serialize(self):
|
def serialize(self):
|
||||||
r = b""
|
r = b""
|
||||||
r += struct.pack("<i", self.type)
|
r += struct.pack("<I", self.type)
|
||||||
r += ser_uint256(self.hash)
|
r += ser_uint256(self.hash)
|
||||||
return r
|
return r
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue