From 591c9f245465a73d839dfd5264e6322e5ae9c902 Mon Sep 17 00:00:00 2001 From: Mathias Agopian Date: Tue, 6 Nov 2018 13:22:56 -0800 Subject: [PATCH] Fix a crasher when allocating the last Job Instead of returning nullptr, the pool allocator returned an invalid pointer. --- libs/utils/include/utils/Allocator.h | 2 +- libs/utils/include/utils/JobSystem.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libs/utils/include/utils/Allocator.h b/libs/utils/include/utils/Allocator.h index 5ed5dcda18..76263cfeb7 100644 --- a/libs/utils/include/utils/Allocator.h +++ b/libs/utils/include/utils/Allocator.h @@ -238,7 +238,7 @@ public: break; } } - return storage + currentHead.offset; + return (currentHead.offset >= 0) ? (storage + currentHead.offset) : nullptr; } void push(void* p) noexcept { diff --git a/libs/utils/include/utils/JobSystem.h b/libs/utils/include/utils/JobSystem.h index c0b1c429e5..85027ca72b 100644 --- a/libs/utils/include/utils/JobSystem.h +++ b/libs/utils/include/utils/JobSystem.h @@ -336,13 +336,13 @@ private: Job* pop(WorkQueue& workQueue) noexcept { size_t index = workQueue.pop(); assert(index <= MAX_JOB_COUNT); - return !index ? nullptr : (mJobStorageBase - 1) + index; + return !index ? nullptr : &mJobStorageBase[index - 1]; } Job* steal(WorkQueue& workQueue) noexcept { size_t index = workQueue.steal(); assert(index <= MAX_JOB_COUNT); - return !index ? nullptr : (mJobStorageBase - 1) + index; + return !index ? nullptr : &mJobStorageBase[index - 1]; } // these have thread contention, keep them together