#2 Incorrect month selection in get_day_num()


When determining if a day is valid, get_day_num() (in
util.cpp) uses 'month' as an index into monthlength[]
and/or monthlenghthleap[]. 'month' has a range of 1..12,
but the valid index values for monthlength[] begin at 0,
making January = 0 and December = 11.

The bug is probably only obvious when a date entered has
a month of December, which fails (assuming
monthlength[12] == 0, which probably isn't always the
case) due to the out of range index.

I'm attaching a patch to util.cpp that changes the index
values from 'month' to 'month-1'. It seems to work,
though I haven't looked to see if a similar change would
be needed elsewhere is the program.

Hope this helps.



  • aturnquist

    aturnquist - 2004-12-31

    Patch to correct month indexing in util.cpp:get_day_num()

  • John Bailey

    John Bailey - 2005-06-05

    Logged In: YES

    This was a valid bug. I accepted your patch with only a
    minor spacing change. I don't know how I missed it when I
    tested, as I fixed an indentical bug elsewhere in timespan.
    Thanks for fixing the bug!

    I apologize for not reviewing this sooner; I did not see it
    or receive an e-mail for it.

  • John Bailey

    John Bailey - 2005-06-05
    • assigned_to: nobody --> rekkanoryo
    • status: open --> closed-fixed

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks