Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions parse_posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,14 @@ timelib_sll timelib_ts_at_start_of_year(timelib_sll year)
timelib_sll epoch_leap_years = count_leap_years(1970);
timelib_sll current_leap_years = count_leap_years(year);

/* FIXME: handle error instead of clamping result */
if (year < (TIMELIB_SLL_MIN / SECS_PER_DAY + epoch_leap_years - current_leap_years) / DAYS_PER_YEAR + 1970) {
return TIMELIB_SLL_MIN;
}
if (year > (TIMELIB_SLL_MAX / SECS_PER_DAY + epoch_leap_years - current_leap_years) / DAYS_PER_YEAR + 1970) {
return TIMELIB_SLL_MAX;
}

return SECS_PER_DAY * (
((year-1970) * DAYS_PER_YEAR)
+ current_leap_years
Expand Down
4 changes: 4 additions & 0 deletions timelib.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,14 @@ typedef uint32_t timelib_ulong;
typedef uint64_t timelib_ull;
typedef int64_t timelib_sll;
# define TIMELIB_LL_CONST(n) n ## i64
# define TIMELIB_SLL_MIN INT64_MIN
# define TIMELIB_SLL_MAX INT64_MAX
#else
typedef unsigned long long timelib_ull;
typedef signed long long timelib_sll;
# define TIMELIB_LL_CONST(n) n ## ll
# define TIMELIB_SLL_MIN LLONG_MIN
# define TIMELIB_SLL_MAX LLONG_MAX
#endif

typedef struct _ttinfo ttinfo;
Expand Down