Procházet zdrojové kódy

Harden security within time module

Patrick-Christopher Mattulat před 1 dnem
rodič
revize
0c8b2c073d

+ 8 - 8
source/ls-std/time/Date.cpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-08-14
- * Changed:         2023-05-24
+ * Changed:         2025-12-21
  *
  * */
 
@@ -28,25 +28,25 @@ Date::Date() : Class("Date")
 
 Date::~Date() noexcept = default;
 
-Date &Date::operator+(int _value)
+Date &Date::operator+(const int _value)
 {
   this->_incrementByDays(_value);
   return *this;
 }
 
-Date &Date::operator-(int _value)
+Date &Date::operator-(const int _value)
 {
   this->_decrementByDays(_value);
   return *this;
 }
 
-Date &Date::operator+=(int _value)
+Date &Date::operator+=(const int _value)
 {
   this->_incrementByDays(_value);
   return *this;
 }
 
-Date &Date::operator-=(int _value)
+Date &Date::operator-=(const int _value)
 {
   this->_decrementByDays(_value);
   return *this;
@@ -97,7 +97,7 @@ time_t Date::getTime() const
   return this->timestamp;
 }
 
-void Date::setTime(time_t _timestamp)
+void Date::setTime(const time_t _timestamp)
 {
   this->timestamp = _timestamp;
   this->_init();
@@ -111,12 +111,12 @@ string Date::toString() const
   return _stream.str();
 }
 
-void Date::_decrementByDays(int _value)
+void Date::_decrementByDays(const int _value)
 {
   this->timestamp -= (_value * 86400);
 }
 
-void Date::_incrementByDays(int _value)
+void Date::_incrementByDays(const int _value)
 {
   this->timestamp += (_value * 86400);
 }

+ 8 - 8
source/ls-std/time/common/DateParameter.cpp

@@ -3,7 +3,7 @@
 * Company:         Lynar Studios
 * E-Mail:          webmaster@lynarstudios.com
 * Created:         2023-03-29
-* Changed:         2023-05-17
+* Changed:         2025-12-21
 *
 * */
 
@@ -17,7 +17,7 @@ using ls::std::time::type::Month;
 using ls::std::time::type::Second;
 using ls::std::time::type::Year;
 
-DateParameter::DateParameter(Year _year, Month _month, Day _day, Hour _hour, Minute _minute, Second _second) : day(_day), hour(_hour), minute(_minute), month(_month), second(_second), year(_year)
+DateParameter::DateParameter(const Year _year, const Month _month, const Day _day, const Hour _hour, const Minute _minute, const Second _second) : day(_day), hour(_hour), minute(_minute), month(_month), second(_second), year(_year)
 {}
 
 DateParameter::DateParameter() = default;
@@ -59,32 +59,32 @@ Year DateParameter::getYear() const
   return this->year;
 }
 
-void DateParameter::setDay(Day _day)
+void DateParameter::setDay(const Day _day)
 {
   this->day = _day;
 }
 
-void DateParameter::setHour(Hour _hour)
+void DateParameter::setHour(const Hour _hour)
 {
   this->hour = _hour;
 }
 
-void DateParameter::setMinute(Minute _minute)
+void DateParameter::setMinute(const Minute _minute)
 {
   this->minute = _minute;
 }
 
-void DateParameter::setMonth(Month _month)
+void DateParameter::setMonth(const Month _month)
 {
   this->month = _month;
 }
 
-void DateParameter::setSecond(Second _second)
+void DateParameter::setSecond(const Second _second)
 {
   this->second = _second;
 }
 
-void DateParameter::setYear(Year _year)
+void DateParameter::setYear(const Year _year)
 {
   this->year = _year;
 }

+ 2 - 2
source/ls-std/time/common/DateParameterMapper.cpp

@@ -3,7 +3,7 @@
 * Company:         Lynar Studios
 * E-Mail:          webmaster@lynarstudios.com
 * Created:         2023-03-31
-* Changed:         2023-05-17
+* Changed:         2025-12-21
 *
 * */
 
@@ -38,7 +38,7 @@ UnixTimestamp DateParameterMapper::toUnixTimestamp(const DateParameter &_datePar
   timeInfo.tm_sec = _dateParameter.getSecond();
   timeInfo.tm_isdst = -1;
 
-  return (UnixTimestamp) mktime(&timeInfo);
+  return static_cast<UnixTimestamp>(mktime(&timeInfo));
 }
 #endif
 

+ 3 - 3
source/ls-std/time/system-time/PosixClock.cpp

@@ -3,7 +3,7 @@
 * Company:         Lynar Studios
 * E-Mail:          webmaster@lynarstudios.com
 * Created:         2023-03-15
-* Changed:         2023-03-31
+* Changed:         2025-12-21
 *
 * */
 
@@ -22,7 +22,7 @@ PosixClock::~PosixClock() noexcept = default;
 
 bool PosixClock::setTime(const DateParameter &_dateParameter)
 {
-  UnixTimestamp timestamp = DateParameterMapper::toUnixTimestamp(_dateParameter);
-  timespec timespec{timestamp, 0};
+  const UnixTimestamp timestamp = DateParameterMapper::toUnixTimestamp(_dateParameter);
+  const timespec timespec{timestamp, 0};
   return clock_settime(CLOCK_REALTIME, &timespec) == 0;
 }

+ 3 - 3
source/ls-std/time/system-time/SystemTime.cpp

@@ -3,7 +3,7 @@
 * Company:         Lynar Studios
 * E-Mail:          webmaster@lynarstudios.com
 * Created:         2023-03-15
-* Changed:         2023-05-18
+* Changed:         2025-12-21
 *
 * */
 
@@ -35,12 +35,12 @@ using std::make_shared;
 using std::shared_ptr;
 using std::string;
 
-SystemTime::SystemTime(const shared_ptr<SystemTimeParameter> &_parameter) : Class(SystemTime::_fetchClassName()), parameter(_parameter)
+SystemTime::SystemTime(const shared_ptr<SystemTimeParameter> &_parameter) : Class(_fetchClassName()), parameter(_parameter)
 {
   NullPointerArgumentEvaluator{_parameter}.evaluate();
 }
 
-SystemTime::SystemTime() : Class(SystemTime::_fetchClassName())
+SystemTime::SystemTime() : Class(_fetchClassName())
 {
   this->_generateParameter();
 }