Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segmentation fault while converting invalid date. #100

Open
amerocu opened this issue Feb 4, 2025 · 0 comments
Open

Segmentation fault while converting invalid date. #100

amerocu opened this issue Feb 4, 2025 · 0 comments

Comments

@amerocu
Copy link

amerocu commented Feb 4, 2025

Constructing some wrong Dates I have managed to reach a segmentation fault error. While I guess building correct dates is a user duty, it seems to me a bit too much to have segmentation fault for these cases.

Attached an example to reproduce.

import Chronos
import Data.Int

validDate =
    Date
      (Year 2025)
      (Month 0) -- valid month January
      (DayOfMonth 10)

validDay = dateToDay validDate
-- λ> validDay
-- Day {getDay = 60685}

brokenDate =
    Date
      (Year 2025)
      (Month (-1)) -- clearly not a valid month
      (DayOfMonth 10)

bangDay = dateToDay brokenDate
-- λ> bangDay
-- Day {getDay = Segmentation fault (core dumped)

alsoBrokenDate =
    Date
      (Year 2025)
      (Month 13) -- also clearly not a valid month
      (DayOfMonth 10)

alsoBangDay = dateToDay alsoBrokenDate
-- λ> alsoBangDay
-- Day {getDay = Segmentation fault (core dumped)

brokenButNotQuiteDate =
    Date
      (Year 2025)
      (Month 12) -- not a valid month 0..11
      (DayOfMonth 10)

notBangButShoudlBangDay = dateToDay brokenButNotQuiteDate
-- λ> notBangButShoudlBangDay
-- Day {getDay = 61040}

what = (dayToDate . dateToDay) brokenButNotQuiteDate
-- λ> what
-- Date { dateYear = Year {getYear = 2025}
--      , dateMonth = Month {getMonth = 11}
--      , dateDay = DayOfMonth {getDayOfMonth = 31}
--      }

As s bonus the roundtrip for Dates on the thirteenth month just does not make sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant