Matter framework safe conversion for known enum (#36015)
* [Matter.framework] MTRConversion.h: error: arithmetic between enumeration type 'chip::(unnamed enum at src/lib/support/TimeUtils.h:99:1)' and floating-point type 'NSTimeInterval' (aka 'double') [-Werror,-Wenum-float-conversion]
* [Matter.framework] MTRConversion.mm: error: arithmetic between floating-point type 'NSTimeInterval' (aka 'double') and enumeration type 'chip::(unnamed enum at src/lib/support/TimeUtils.h:32:1)' [-Werror,-Wenum-float-conversion]
* [Matter.framework] MTRBaseDevice.mm: error: arithmetic between floating-point type 'NSTimeInterval' (aka 'double') and enumeration type 'chip::(unnamed enum at lib/support/TimeUtils.h:32:1)' [-Werror,-Wenum-float-conversion
diff --git a/src/darwin/Framework/CHIP/MTRBaseDevice.mm b/src/darwin/Framework/CHIP/MTRBaseDevice.mm
index 89f7aab..f21fc5b 100644
--- a/src/darwin/Framework/CHIP/MTRBaseDevice.mm
+++ b/src/darwin/Framework/CHIP/MTRBaseDevice.mm
@@ -1894,7 +1894,7 @@
uint64_t eventTimestampValueSeconds = timeValue / chip::kMillisecondsPerSecond;
uint64_t eventTimestampValueRemainderMilliseconds = timeValue % chip::kMillisecondsPerSecond;
NSTimeInterval eventTimestampValueRemainder
- = NSTimeInterval(eventTimestampValueRemainderMilliseconds) / chip::kMillisecondsPerSecond;
+ = NSTimeInterval(eventTimestampValueRemainderMilliseconds / static_cast<uint64_t>(chip::kMillisecondsPerSecond));
NSTimeInterval eventTimestampValue = eventTimestampValueSeconds + eventTimestampValueRemainder;
return eventTimestampValue;
diff --git a/src/darwin/Framework/CHIP/MTRConversion.h b/src/darwin/Framework/CHIP/MTRConversion.h
index b0cf1af..6f722d0 100644
--- a/src/darwin/Framework/CHIP/MTRConversion.h
+++ b/src/darwin/Framework/CHIP/MTRConversion.h
@@ -38,7 +38,8 @@
inline NSDate * MatterEpochSecondsAsDate(uint32_t matterEpochSeconds)
{
- return [NSDate dateWithTimeIntervalSince1970:(chip::kChipEpochSecondsSinceUnixEpoch + (NSTimeInterval) matterEpochSeconds)];
+ const uint64_t interval = static_cast<uint32_t>(chip::kChipEpochSecondsSinceUnixEpoch) + matterEpochSeconds;
+ return [NSDate dateWithTimeIntervalSince1970:(NSTimeInterval) interval];
}
template <typename Rep, typename Period>
diff --git a/src/darwin/Framework/CHIP/MTRConversion.mm b/src/darwin/Framework/CHIP/MTRConversion.mm
index 5e657b9..3b0b734 100644
--- a/src/darwin/Framework/CHIP/MTRConversion.mm
+++ b/src/darwin/Framework/CHIP/MTRConversion.mm
@@ -92,7 +92,7 @@
bool DateToMatterEpochMicroseconds(NSDate * date, uint64_t & matterEpochMicroseconds)
{
- uint64_t timeSinceUnixEpoch = static_cast<uint64_t>(date.timeIntervalSince1970 * chip::kMicrosecondsPerSecond);
+ uint64_t timeSinceUnixEpoch = static_cast<uint64_t>(date.timeIntervalSince1970 * static_cast<double>(chip::kMicrosecondsPerSecond));
if (timeSinceUnixEpoch < chip::kChipEpochUsSinceUnixEpoch) {
// This is a pre-Matter-epoch time, and cannot be represented as an epoch time value.
return false;