Skip to content

Commit 2468b35

Browse files
committed
Merge #380: Use != 0 instead of == 1 for check of masked value
b747e51 Use != 0 instead of == 1 for check of masked value (Tobin C. Harding) Pull request description: Recently [0] we added a check on a value masked against `SEQUENCE_LOCKTIME_DISABLE_FLAG`, this check uses `x == 1` but x can never be zero since `SEQUENCE_LOCKTIME_DISABLE_FLAG` is equal to `0x80000000`. Looking at the original commit it looks like we are trying to check for a value _higher_ than the flag value, so we can mask then use `x != 0` to see if the flag bit is enabled. Found by clippy: error: incompatible bit mask: `_ & 2147483648` can never be equal to `1` CC: @darosior, have I understood this correctly man? [0] commit: `commit a3dd9fe` ACKs for top commit: darosior: Oh, right 🤦. Good catch. ACK b747e51. sanket1729: Wow. Thanks for catching this bug! ACK b747e51 Tree-SHA512: ee609ee39eaf23960e205ab7b4b44b04dc59f4bb175cd532af64eb3ffd5e3325e910efa327d30334c7947f607d93c4b4362d6a89706a3013aa11a912e6b27528
2 parents 225e9d3 + b747e51 commit 2468b35

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/miniscript/types/extra_props.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,7 +1037,7 @@ impl Property for ExtData {
10371037
// Note that for CLTV this is a limitation not of Bitcoin but Miniscript. The
10381038
// number on the stack would be a 5 bytes signed integer but Miniscript's B type
10391039
// only consumes 4 bytes from the stack.
1040-
if t == 0 || (t & SEQUENCE_LOCKTIME_DISABLE_FLAG) == 1 {
1040+
if t == 0 || (t & SEQUENCE_LOCKTIME_DISABLE_FLAG) != 0 {
10411041
return Err(Error {
10421042
fragment: fragment.clone(),
10431043
error: ErrorKind::InvalidTime,
@@ -1046,7 +1046,7 @@ impl Property for ExtData {
10461046
Ok(Self::from_after(t))
10471047
}
10481048
Terminal::Older(t) => {
1049-
if t == 0 || (t & SEQUENCE_LOCKTIME_DISABLE_FLAG) == 1 {
1049+
if t == 0 || (t & SEQUENCE_LOCKTIME_DISABLE_FLAG) != 0 {
10501050
return Err(Error {
10511051
fragment: fragment.clone(),
10521052
error: ErrorKind::InvalidTime,

src/miniscript/types/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ pub trait Property: Sized {
439439
// Note that for CLTV this is a limitation not of Bitcoin but Miniscript. The
440440
// number on the stack would be a 5 bytes signed integer but Miniscript's B type
441441
// only consumes 4 bytes from the stack.
442-
if t == 0 || (t & SEQUENCE_LOCKTIME_DISABLE_FLAG) == 1 {
442+
if t == 0 || (t & SEQUENCE_LOCKTIME_DISABLE_FLAG) != 0 {
443443
return Err(Error {
444444
fragment: fragment.clone(),
445445
error: ErrorKind::InvalidTime,
@@ -448,7 +448,7 @@ pub trait Property: Sized {
448448
Ok(Self::from_after(t))
449449
}
450450
Terminal::Older(t) => {
451-
if t == 0 || (t & SEQUENCE_LOCKTIME_DISABLE_FLAG) == 1 {
451+
if t == 0 || (t & SEQUENCE_LOCKTIME_DISABLE_FLAG) != 0 {
452452
return Err(Error {
453453
fragment: fragment.clone(),
454454
error: ErrorKind::InvalidTime,
@@ -822,7 +822,7 @@ impl Property for Type {
822822
// Note that for CLTV this is a limitation not of Bitcoin but Miniscript. The
823823
// number on the stack would be a 5 bytes signed integer but Miniscript's B type
824824
// only consumes 4 bytes from the stack.
825-
if t == 0 || (t & SEQUENCE_LOCKTIME_DISABLE_FLAG) == 1 {
825+
if t == 0 || (t & SEQUENCE_LOCKTIME_DISABLE_FLAG) != 0 {
826826
return Err(Error {
827827
fragment: fragment.clone(),
828828
error: ErrorKind::InvalidTime,
@@ -831,7 +831,7 @@ impl Property for Type {
831831
Ok(Self::from_after(t))
832832
}
833833
Terminal::Older(t) => {
834-
if t == 0 || (t & SEQUENCE_LOCKTIME_DISABLE_FLAG) == 1 {
834+
if t == 0 || (t & SEQUENCE_LOCKTIME_DISABLE_FLAG) != 0 {
835835
return Err(Error {
836836
fragment: fragment.clone(),
837837
error: ErrorKind::InvalidTime,

0 commit comments

Comments
 (0)