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;
} }
if (mem_) {
// Bump-ptr allocation. // Bump-ptr allocation.
if (intptr_t(mem_) % 128 == 0) { if (intptr_t(mem_) % 128 == 0) {
// Avoid allocating pointers that may look like malloc // Avoid allocating pointers that may look like malloc
// pointers. // pointers.
mem_ += std::min(sz_, max_align_v); mem_ += std::min(sz_, max_align_v);
} }
if (mem_ && (mem_ + sz_ <= end_)) { if (mem_ + sz_ <= end_) {
auto mem = mem_; auto mem = mem_;
mem_ += sz_; 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