Skip to content

Commit 540038d

Browse files
committed
Merge rust-bitcoin#4216: Replace underflow with overflow in doc comments
a273814 Replace underflow with overflow in doc comments (yancy) 2f897e2 Remove warning section (yancy) Pull request description: The use of underflow is misleading. Adding one to MAX and subtracting one from MIN are both considered an overflow. Note I tried to keep to 80 column line length so a paragraph needed some shuffling. closes rust-bitcoin#4187 ACKs for top commit: Kixunil: ACK a273814 tcharding: ACK a273814 apoelstra: ACK a273814; successfully ran local tests Tree-SHA512: 3d1fd3a6c3e11694d189086b6f9e14d55b912497dca8bac2153cc54afbbbee527cae354e60781f8b61591b13aa85fb9e490cea2e7aed3dd9d3e4335502ffb84b
2 parents 3bb1a7a + a273814 commit 540038d

File tree

5 files changed

+6
-17
lines changed

5 files changed

+6
-17
lines changed

bitcoin/src/blockdata/script/instruction.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ impl<'a> InstructionIndices<'a> {
231231
let prev_remaining = self.remaining_bytes();
232232
let prev_pos = self.pos;
233233
let instruction = next_fn(self)?;
234-
// No underflow: there must be less remaining bytes now than previously
234+
// No overflow: there must be less remaining bytes now than previously
235235
let consumed = prev_remaining - self.remaining_bytes();
236236
// No overflow: sum will never exceed slice length which itself can't exceed `usize`
237237
self.pos += consumed;

bitcoin/src/taproot/serialized_signature.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ mod into_iter {
217217

218218
#[inline]
219219
fn size_hint(&self) -> (usize, Option<usize>) {
220-
// can't underflow thanks to the invariant
220+
// can't overflow thanks to the invariant
221221
let len = self.signature.len() - self.pos;
222222
(len, Some(len))
223223
}

units/src/amount/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -588,8 +588,8 @@ enum DisplayStyle {
588588

589589
/// Calculates the sum over the iterator using checked arithmetic.
590590
pub trait CheckedSum<R>: sealed::Sealed<R> {
591-
/// Calculates the sum over the iterator using checked arithmetic. If an over or underflow would
592-
/// happen it returns [`None`].
591+
/// Calculates the sum over the iterator using checked arithmetic. If an
592+
/// overflow happens it returns [`None`].
593593
fn checked_sum(self) -> Option<R>;
594594
}
595595

units/src/amount/signed.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ use super::{
2525
/// Warning!
2626
///
2727
/// This type implements several arithmetic operations from [`core::ops`].
28-
/// To prevent errors due to overflow or underflow when using these operations,
28+
/// To prevent errors due to an overflow when using these operations,
2929
/// it is advised to instead use the checked arithmetic methods whose names
3030
/// start with `checked_`. The operations from [`core::ops`] that [`SignedAmount`]
31-
/// implements will panic when overflow or underflow occurs.
31+
/// implements will panic when an overflow occurs.
3232
///
3333
/// # Examples
3434
///

units/src/amount/unsigned.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,6 @@ use super::{
2222
/// conversion to various denominations. The [`Amount`] type does not implement [`serde`] traits
2323
/// but we do provide modules for serializing as satoshis or bitcoin.
2424
///
25-
/// Warning!
26-
///
27-
/// This type implements several arithmetic operations from [`core::ops`].
28-
/// To prevent errors due to overflow or underflow when using these operations,
29-
/// it is advised to instead use the checked arithmetic methods whose names
30-
/// start with `checked_`. The operations from [`core::ops`] that [`Amount`]
31-
/// implements will panic when overflow or underflow occurs. Also note that
32-
/// since the internal representation of amounts is unsigned, subtracting below
33-
/// zero is considered an underflow and will cause a panic if you're not using
34-
/// the checked arithmetic methods.
35-
///
3625
/// # Examples
3726
///
3827
/// ```

0 commit comments

Comments
 (0)