clarinet
clarinet copied to clipboard
fix: add overflow/underflow protection to counter example contracts
Description
Fixes compiler warnings about "use of potentially unchecked data" in the counter example contracts by adding proper overflow and underflow protection.
Changes
- Add pre-operation validation to prevent arithmetic overflow in
incrementfunction - Add pre-operation validation to prevent underflow in
decrementfunction - Return error
u1on overflow attempt,u2on underflow attempt - Add comprehensive tests to verify overflow/underflow protection
Testing
- All existing tests pass
- Added new test for underflow protection
- Added new test for overflow protection (u128 max value)
- No compiler warnings (
clarinet checkpasses cleanly)
Impact
- Provides safer example code for developers learning Clarity
- Demonstrates best practices for arithmetic operations
- Eliminates all warnings from the counter example contracts
Since this is just an example, I'd like to keep it simple. What do you think?