Missing Error Check on time() Calls

This commit is contained in:
2025-12-07 19:04:00 +01:00
parent f303f9f032
commit d82c45057b

View File

@ -148,12 +148,20 @@ void Drive::setDriveSMARTData(string modelFamily,
void Drive::setTimestamp() void Drive::setTimestamp()
{ {
time(&this->u32Timestamp); if (time(&this->u32Timestamp) == -1)
{
// handle error
this->u32Timestamp = 0U;
}
} }
void Drive::setActionStartTimestamp() void Drive::setActionStartTimestamp()
{ {
time(&this->u32TimestampTaskStart); if (time(&this->u32TimestampTaskStart) == -1)
{
// handle error
this->u32TimestampTaskStart = 0U;
}
} }
time_t Drive::getActionStartTimestamp() time_t Drive::getActionStartTimestamp()
@ -164,7 +172,11 @@ time_t Drive::getActionStartTimestamp()
void Drive::calculateTaskDuration() void Drive::calculateTaskDuration()
{ {
time_t u32localtime; time_t u32localtime;
time(&u32localtime); if (time(&u32localtime) == -1)
{
// handle error
u32localtime = 0U;
}
this->u32TaskDuration = u32localtime - this->u32TimestampTaskStart; this->u32TaskDuration = u32localtime - this->u32TimestampTaskStart;
} }
@ -178,6 +190,11 @@ void Drive::checkFrozenDrive(void)
{ {
time_t u32localtime; time_t u32localtime;
time(&u32localtime); time(&u32localtime);
if (time(&u32localtime) == -1)
{
// handle error
u32localtime = 0U;
}
if ((u32localtime - this->u32Timestamp) >= (FROZEN_TIMEOUT * 60) && (this->u32Timestamp > 0) && (this->getTaskPercentage() < 100.0)) if ((u32localtime - this->u32Timestamp) >= (FROZEN_TIMEOUT * 60) && (this->u32Timestamp > 0) && (this->getTaskPercentage() < 100.0))
{ {