Skip to content

Commit 7bdae14

Browse files
committed
Merge rust-bitcoin/rust-bitcoin#809: Use write_all instead of write
22aeaef Use write_all instead of write (Riccardo Casatta) Pull request description: write() could write only a part of the given buffer, the caller should check the numbers of byte written (which is what write_all does) ACKs for top commit: apoelstra: ACK 22aeaef Kixunil: ACK 22aeaef dr-orlovsky: utACK 22aeaef Tree-SHA512: e4bf3c757e1d369f9bb737e970b93ec29a487419eb478b41c36da033eafea3f0a96faa1e5c6f9397febba309ce4330b29a9e5369bb547645e5f72ba935d2cafe
2 parents da3f3eb + 915b044 commit 7bdae14

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

src/util/bip32.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,7 @@ impl ExtendedPubKey {
770770
/// Returns the HASH160 of the chaincode
771771
pub fn identifier(&self) -> XpubIdentifier {
772772
let mut engine = XpubIdentifier::engine();
773-
engine.write(&self.public_key.serialize()).expect("engines don't error");
773+
engine.write_all(&self.public_key.serialize()).expect("engines don't error");
774774
XpubIdentifier::from_engine(engine)
775775
}
776776

src/util/psbt/raw.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ impl<Subtype> Encodable for ProprietaryKey<Subtype> where Subtype: Copy + From<u
147147
fn consensus_encode<W: io::Write>(&self, mut e: W) -> Result<usize, io::Error> {
148148
let mut len = self.prefix.consensus_encode(&mut e)? + 1;
149149
e.emit_u8(self.subtype.into())?;
150-
len += e.write(&self.key)?;
150+
e.write_all(&self.key)?;
151+
len += self.key.len();
151152
Ok(len)
152153
}
153154
}

src/util/taproot.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -615,11 +615,10 @@ impl TaprootMerkleBranch {
615615

616616
/// Serialize to a writer. Returns the number of bytes written
617617
pub fn encode<Write: io::Write>(&self, mut writer: Write) -> io::Result<usize> {
618-
let mut written = 0;
619618
for hash in self.0.iter() {
620-
written += writer.write(hash)?;
619+
writer.write_all(hash)?;
621620
}
622-
Ok(written)
621+
Ok(self.0.len() * sha256::Hash::LEN)
623622
}
624623

625624
/// Serialize self as bytes
@@ -704,11 +703,10 @@ impl ControlBlock {
704703
/// Serialize to a writer. Returns the number of bytes written
705704
pub fn encode<Write: io::Write>(&self, mut writer: Write) -> io::Result<usize> {
706705
let first_byte: u8 = i32::from(self.output_key_parity) as u8 | self.leaf_version.to_consensus();
707-
let mut bytes_written = 0;
708-
bytes_written += writer.write(&[first_byte])?;
709-
bytes_written += writer.write(&self.internal_key.serialize())?;
710-
bytes_written += self.merkle_branch.encode(&mut writer)?;
711-
Ok(bytes_written)
706+
writer.write_all(&[first_byte])?;
707+
writer.write_all(&self.internal_key.serialize())?;
708+
self.merkle_branch.encode(&mut writer)?;
709+
Ok(self.size())
712710
}
713711

714712
/// Serialize the control block. This would be required when

0 commit comments

Comments
 (0)