Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Uuid comparison for PROGMEM usage #2567

Merged
merged 1 commit into from
Oct 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Sming/Core/Data/Uuid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ uint32_t os_random();
void os_get_random(void* buf, size_t n);
}

bool Uuid::operator==(const Uuid& other) const
{
// Ensure these are stricly compared as a set of words to avoid PROGMEM issues
struct S {
uint32_t a, b, c, d;
};
auto& s1 = reinterpret_cast<const S&>(*this);
auto& s2 = reinterpret_cast<const S&>(other);
return s1.a == s2.a && s1.b == s2.b && s1.c == s2.c && s1.d == s2.d;
}

bool Uuid::generate(MacAddress mac)
{
uint8_t version = 1; // DCE version
Expand Down
10 changes: 3 additions & 7 deletions Sming/Core/Data/Uuid.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ struct Uuid {
*/
static constexpr size_t stringSize = 36;

Uuid()
constexpr Uuid()
{
}

Expand Down Expand Up @@ -69,14 +69,10 @@ struct Uuid {

explicit operator bool() const
{
Uuid Null{};
return memcmp(this, &Null, sizeof(Null)) != 0;
return *this != Uuid{};
}

bool operator==(const Uuid& other) const
{
return memcmp(this, &other, sizeof(Uuid)) == 0;
}
bool operator==(const Uuid& other) const;

bool operator!=(const Uuid& other) const
{
Expand Down