Skip to content

Commit

Permalink
Explicitly call the EndianPutSigned for signed integers. (project-chi…
Browse files Browse the repository at this point in the history
…p#28374)

* Explicitly call the EndianPutSigned for signed integers.

* Added constexpr to compile for Android.
  • Loading branch information
hicklin authored and Alexi Poth committed Aug 15, 2023
1 parent f1d6693 commit 71562a4
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/app/SafeAttributePersistenceProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,14 @@ class SafeAttributePersistenceProvider
{
uint8_t value[sizeof(T)];
auto w = Encoding::LittleEndian::BufferWriter(value, sizeof(T));
w.EndianPut(uint64_t(aValue), sizeof(T));
if constexpr (std::is_signed_v<T>)
{
w.EndianPutSigned(aValue, sizeof(T));
}
else
{
w.EndianPut(aValue, sizeof(T));
}

return SafeWriteValue(aPath, ByteSpan(value));
}
Expand All @@ -76,7 +83,7 @@ class SafeAttributePersistenceProvider
return err;
}

chip::Encoding::LittleEndian::Reader r(tempVal.data(), tempVal.size());
Encoding::LittleEndian::Reader r(tempVal.data(), tempVal.size());
r.RawReadLowLevelBeCareful(&aValue);
return r.StatusCode();
}
Expand Down

0 comments on commit 71562a4

Please sign in to comment.