Skip to content

Commit

Permalink
Explicitly call the EndianPutSigned for signed integers. (#28374)
Browse files Browse the repository at this point in the history
* Explicitly call the EndianPutSigned for signed integers.

* Added constexpr to compile for Android.
  • Loading branch information
hicklin authored and pull[bot] committed Feb 8, 2024
1 parent 0d4cc9c commit 2103123
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 2103123

Please sign in to comment.