Skip to content

Commit

Permalink
Fix bounds checking in SetRegsiterBit and ClearRegisterBit - fixes #631
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianstevens committed Apr 24, 2023
1 parent e87fad2 commit 9650c96
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ public IDigitalInputPort CreateDigitalInputPort(

private void SetRegisterBit(byte register, int bit)
{
if (bit >= 7 || bit < 0) { throw new ArgumentOutOfRangeException(); }
if (bit > 7 || bit < 0) { throw new ArgumentOutOfRangeException(); }

var value = mcpDevice.ReadRegister(register);
value |= (byte)(1 << bit);
Expand All @@ -319,7 +319,7 @@ private void SetRegisterBit(byte register, int bit)

private void ClearRegisterBit(byte register, int bit)
{
if (bit >= 7 || bit < 0) { throw new ArgumentOutOfRangeException(); }
if (bit > 7 || bit < 0) { throw new ArgumentOutOfRangeException(); }
var value = mcpDevice.ReadRegister(register);
value &= (byte)~(1 << bit);
mcpDevice.WriteRegister(register, value);
Expand Down

0 comments on commit 9650c96

Please sign in to comment.