Commit 3e9865fc authored by Igor Sugak's avatar Igor Sugak Committed by Facebook GitHub Bot

fix nullptr-with-nonzero-offset UB in CacheLocality.h

Reviewed By: yfeldblum, andriigrynenko

Differential Revision: D29914176

fbshipit-source-id: 981b75acec24391822ace833d4265fed0c5d0cb3
parent c22c915d
...@@ -382,20 +382,21 @@ class SimpleAllocator { ...@@ -382,20 +382,21 @@ class SimpleAllocator {
return mem; return mem;
} }
// Bump-ptr allocation. if (mem_) {
if (intptr_t(mem_) % 128 == 0) { // Bump-ptr allocation.
// Avoid allocating pointers that may look like malloc if (intptr_t(mem_) % 128 == 0) {
// pointers. // Avoid allocating pointers that may look like malloc
mem_ += std::min(sz_, max_align_v); // pointers.
} mem_ += std::min(sz_, max_align_v);
if (mem_ && (mem_ + sz_ <= end_)) { }
auto mem = mem_; if (mem_ + sz_ <= end_) {
mem_ += sz_; auto mem = mem_;
mem_ += sz_;
assert(intptr_t(mem) % 128 != 0); assert(intptr_t(mem) % 128 != 0);
return mem; return mem;
}
} }
return allocateHard(); return allocateHard();
} }
void deallocate(void* mem) { void deallocate(void* mem) {
......
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