input-output-hk / input-output-hk/cuddle
genControl .lt crashes when controller literal is 0
- Dominant language
- Haskell
- Stars
- 7
- Forks
- 5
- PR merge metrics
- No merged PRs in 30d
Description
## Description
`genControl` crashes when the `.lt` operator is used with a controller literal of 0, because `choose` receives an invalid range.
## Location
`src/Codec/CBOR/Cuddle/CBOR/Gen.hs`, `genControl` function
## Details
```haskell
(CtlOp.Lt, CTree.Literal (Value (VUInt n) _)) -> case target of
CTree.Postlude PTUInt -> S . TInteger <$> choose (0, fromIntegral n - 1)
```
When `n == 0`, `choose (0, fromIntegral n - 1)` becomes `choose (0, -1)`, which is an invalid range.
## Suggested fix
Handle `n == 0` explicitly with a clear error message about the empty range (there are no unsigned integers less than 0).
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.