#1422 closed defect (fixed)

TOD_Validate incorrect time processing

Reported by: Nickolay Semyonov-Kolchin Owned by: Joel Sherrill
Priority: normal Milestone: 4.10
Component: score Version: 4.10
Severity: minor Keywords:
Cc: sebastian.huber@…, fjdpedrosa@…, gedare@… Blocked By:
Blocking:

Description

Our partners found two minor bugs in _TOD_Validate function:

  1. Leap year calculation is incorrect:

if(the_tod->year % 4 == 0)

is not enough. Correct way is:

if(

((the_tod->year % 4) == 0 && (the_tod->year % 100 != 0))

(the_tod->year % 400 == 0))

Reference: http://en.wikipedia.org/wiki/Leap_year

  1. The maximum possible year is 2038. Setting year to bigger value will

produce wrong result in current 32-bit RTEMS. (I never heard about RTEMS running on 64-bit platforms, though).

Patch that fix both problems attached.

Attachments (3)

tod.patch (1.3 KB) - added by Nickolay Semyonov-Kolchin on Jun 4, 2009 at 2:54:40 PM.
correct leap year calculation,
0001-Fix-leap-year-calculation.patch (991 bytes) - added by Chirayu Desai on Dec 5, 2013 at 12:00:46 PM.
Fix only the leap year calcuation.
0001-sptest-sp2038-Add-a-test-for-leap-year.patch (1.7 KB) - added by Chirayu Desai on Dec 5, 2013 at 3:52:56 PM.
Testcase

Download all attachments as: .zip

Change History (7)

Changed on Jun 4, 2009 at 2:54:40 PM by Nickolay Semyonov-Kolchin

Attachment: tod.patch added

correct leap year calculation,

comment:1 Changed on Nov 10, 2009 at 5:07:57 PM by Filipe Pedrosa

Cc: Filipe Pedrosa added

Changed on Dec 5, 2013 at 12:00:46 PM by Chirayu Desai

Fix only the leap year calcuation.

comment:2 Changed on Dec 5, 2013 at 1:45:41 PM by Gedare Bloom

Cc: Gedare Bloom added

comment:3 Changed on Dec 5, 2013 at 1:51:53 PM by Sebastian Huber

Cc: Sebastian Huber added

Changed on Dec 5, 2013 at 3:52:56 PM by Chirayu Desai

Testcase

comment:4 Changed on Dec 5, 2013 at 3:58:11 PM by Gedare Bloom

Resolution: fixed
Status: newclosed

I committed the leap year test and fix. TI think the 2038 problem is addressed elsewhere perhaps. If not a new PR can be filed.

Note: See TracTickets for help on using tickets.