Skip to content

Commit

Permalink
Matter framework safe conversion for known enum (#36015)
Browse files Browse the repository at this point in the history
* [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
  • Loading branch information
vivien-apple authored and pull[bot] committed Nov 5, 2024
1 parent 1154ef0 commit 3319865
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/darwin/Framework/CHIP/MTRBaseDevice.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1894,7 +1894,7 @@ NSTimeInterval MTRTimeIntervalForEventTimestampValue(uint64_t timeValue)
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;
Expand Down
3 changes: 2 additions & 1 deletion src/darwin/Framework/CHIP/MTRConversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ AsNumber(chip::Optional<T> optional)

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>
Expand Down
2 changes: 1 addition & 1 deletion src/darwin/Framework/CHIP/MTRConversion.mm
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ bool DateToMatterEpochMilliseconds(NSDate * date, uint64_t & matterEpochMillisec

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;
Expand Down

0 comments on commit 3319865

Please sign in to comment.