Commit 96f74144 authored by Nathan Bronson's avatar Nathan Bronson Committed by Facebook Github Bot

avoid -Wclass-memaccess warning on gcc 9.1

Summary:
F14TestUtil's SwapTrackingAlloc's metadata accesses were
triggering a -Wclass-memaccess warning in gcc 9.1 despite being safe. This
diff changes the accesses to use explicit casting to avoid the warning.

Reviewed By: yfeldblum

Differential Revision: D15393963

fbshipit-source-id: 088811354f00d623a58678c3f41a0e8effdb5ce3
parent 354223ec
......@@ -397,7 +397,8 @@ class SwapTrackingAlloc {
std::size_t extra =
std::max<std::size_t>(1, sizeof(std::size_t) / sizeof(T));
T* p = a_.allocate(extra + n);
std::memcpy(p, &n, sizeof(std::size_t));
void* raw = static_cast<void*>(p);
*static_cast<std::size_t*>(raw) = n;
return p + extra;
}
void deallocate(T* p, size_t n) {
......@@ -406,7 +407,8 @@ class SwapTrackingAlloc {
std::size_t extra =
std::max<std::size_t>(1, sizeof(std::size_t) / sizeof(T));
std::size_t check;
std::memcpy(&check, p - extra, sizeof(std::size_t));
void* raw = static_cast<void*>(p - extra);
check = *static_cast<std::size_t*>(raw);
FOLLY_SAFE_CHECK(check == n, "");
a_.deallocate(p - extra, n + extra);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment