Skip to content

genEnum crashes on empty group #167

Description

@Soupstraw

Description

genEnum crashes when given an empty group because choose receives an invalid range.

Location

src/Codec/CBOR/Cuddle/CBOR/Gen.hs, genEnum function

Details

genEnum tree = case tree of
  CTree.Group trees -> do
    ix <- choose (0, length trees - 1)
    genForCTree $ trees !! ix

When trees is empty, choose (0, length trees - 1) becomes choose (0, -1), which is an invalid range.

Suggested fix

Handle empty groups explicitly with a clear error message before calling choose.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions