Skip to content

Commit

Permalink
Fixed year 2038 crash
Browse files Browse the repository at this point in the history
Fixes #3379
  • Loading branch information
AdamPlenty committed Jul 29, 2024
1 parent 78685e0 commit e21d907
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 26 deletions.
38 changes: 23 additions & 15 deletions src/bflib_basics.c
Original file line number Diff line number Diff line change
Expand Up @@ -441,36 +441,44 @@ int LbLog(struct TbLog *log, const char *fmt_str, va_list arg)
if ((log->flags & LbLog_TimeInHeader) != 0)
{
struct TbTime curr_time;
LbTime(&curr_time);
fprintf(file, " @ %02d:%02d:%02d",
curr_time.Hour,curr_time.Minute,curr_time.Second);
if (LbTime(&curr_time) == Lb_SUCCESS)
{
fprintf(file, " @ %02u:%02u:%02u",
curr_time.Hour,curr_time.Minute,curr_time.Second);
}
at_used = 1;
}
if ((log->flags & LbLog_DateInHeader) != 0)
{
struct TbDate curr_date;
LbDate(&curr_date);
const char *sep;
if ( at_used )
sep = " ";
else
sep = " @ ";
fprintf(file," %s%02d-%02d-%d",sep,curr_date.Day,curr_date.Month,curr_date.Year);
if (LbDate(&curr_date) == Lb_SUCCESS)
{
const char *sep;
if ( at_used )
sep = " ";
else
sep = " @ ";
fprintf(file," %s%02u-%02u-%u",sep,curr_date.Day,curr_date.Month,curr_date.Year);
}
}
fprintf(file, "\n\n");
}
if ((log->flags & LbLog_DateInLines) != 0)
{
struct TbDate curr_date;
LbDate(&curr_date);
fprintf(file,"%02d-%02d-%d ",curr_date.Day,curr_date.Month,curr_date.Year);
if (LbDate(&curr_date) == Lb_SUCCESS)
{
fprintf(file,"%02u-%02u-%u ",curr_date.Day,curr_date.Month,curr_date.Year);
}
}
if ((log->flags & LbLog_TimeInLines) != 0)
{
struct TbTime curr_time;
LbTime(&curr_time);
fprintf(file, "%02d:%02d:%02d ",
curr_time.Hour,curr_time.Minute,curr_time.Second);
if (LbTime(&curr_time) == Lb_SUCCESS)
{
fprintf(file, "%02u:%02u:%02u ",
curr_time.Hour,curr_time.Minute,curr_time.Second);
}
}
if (log->prefix[0] != '\0') {
fputs(log->prefix, file);
Expand Down
3 changes: 3 additions & 0 deletions src/bflib_basics.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
* (at your option) any later version.
*/
/******************************************************************************/
#define _FILE_OFFSET_BITS 64
#define _TIME_BITS 64

#ifndef BFLIB_BASICS_H
#define BFLIB_BASICS_H

Expand Down
26 changes: 15 additions & 11 deletions src/bflib_datetm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,20 +197,24 @@ TbResult LbDateTime(struct TbDate *curr_date, struct TbTime *curr_time)

TbResult LbDateTimeDecode(const time_t *datetime,struct TbDate *curr_date,struct TbTime *curr_time)
{
struct tm *ltime=localtime(datetime);
if (curr_date!=NULL)
struct tm *ltime = localtime(datetime);
if (ltime == NULL)
{
curr_date->Day=ltime->tm_mday;
curr_date->Month=ltime->tm_mon+1;
curr_date->Year=1900+ltime->tm_year;
curr_date->DayOfWeek=ltime->tm_wday;
return Lb_FAIL;
}
if (curr_time!=NULL)
if (curr_date != NULL)
{
curr_time->Hour=ltime->tm_hour;
curr_time->Minute=ltime->tm_min;
curr_time->Second=ltime->tm_sec;
curr_time->HSecond=0;
curr_date->Day = ltime->tm_mday;
curr_date->Month = ltime->tm_mon+1;
curr_date->Year = 1900+ltime->tm_year;
curr_date->DayOfWeek = ltime->tm_wday;
}
if (curr_time != NULL)
{
curr_time->Hour = ltime->tm_hour;
curr_time->Minute = ltime->tm_min;
curr_time->Second = ltime->tm_sec;
curr_time->HSecond = 0;
}
return Lb_SUCCESS;
}
Expand Down

0 comments on commit e21d907

Please sign in to comment.