From ffa88289a797e999c7155c5604d3ef0c4f6fc4ae Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Fri, 24 Apr 2020 20:06:38 +0100 Subject: [PATCH] Pool::Loan::get(): Return nullptr if has no item. Instead of deferencing the nullptr item. Upstreaming change cl/308295787. --- include/marl/pool.h | 2 +- src/pool_test.cpp | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/include/marl/pool.h b/include/marl/pool.h index 393b457..70d53c9 100644 --- a/include/marl/pool.h +++ b/include/marl/pool.h @@ -192,7 +192,7 @@ T* Pool::Loan::operator->() const { template T* Pool::Loan::get() const { - return item->get(); + return item ? item->get() : nullptr; } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/pool_test.cpp b/src/pool_test.cpp index 6ae8f25..eec09b5 100644 --- a/src/pool_test.cpp +++ b/src/pool_test.cpp @@ -26,6 +26,16 @@ TEST_P(WithBoundScheduler, BoundedPool_ConstructDestruct) { marl::BoundedPool pool; } +TEST_P(WithBoundScheduler, UnboundedPoolLoan_GetNull) { + marl::UnboundedPool::Loan loan; + ASSERT_EQ(loan.get(), nullptr); +} + +TEST_P(WithBoundScheduler, BoundedPoolLoan_GetNull) { + marl::BoundedPool::Loan loan; + ASSERT_EQ(loan.get(), nullptr); +} + TEST_P(WithBoundScheduler, UnboundedPool_Borrow) { marl::UnboundedPool pool; for (int i = 0; i < 100; i++) {