Skip to content

Commit 6f7995f

Browse files
celskeggsLeStarch
andauthored
Clarify allocation failure error (#3566)
* Clarify allocation failure error It's not useful to report an UNKNOWN_ERROR when the cause is known. * Adding model to CPP enum check --------- Co-authored-by: M Starch <LeStarch@googlemail.com>
1 parent 4a082e2 commit 6f7995f

4 files changed

Lines changed: 8 additions & 4 deletions

File tree

Os/Generic/PriorityQueue.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,28 +53,28 @@ QueueInterface::Status PriorityQueue::create(const Fw::StringBase& name, FwSizeT
5353
// Allocate indices list
5454
FwSizeType* indices = new (std::nothrow) FwSizeType[depth];
5555
if (indices == nullptr) {
56-
return QueueInterface::Status::UNKNOWN_ERROR;
56+
return QueueInterface::Status::ALLOCATION_FAILED;
5757
}
5858
// Allocate sizes list or clean-up
5959
FwSizeType* sizes = new (std::nothrow) FwSizeType[depth];
6060
if (sizes == nullptr) {
6161
delete[] indices;
62-
return QueueInterface::Status::UNKNOWN_ERROR;
62+
return QueueInterface::Status::ALLOCATION_FAILED;
6363
}
6464
// Allocate sizes list or clean-up
6565
U8* data = new (std::nothrow) U8[depth * messageSize];
6666
if (data == nullptr) {
6767
delete[] indices;
6868
delete[] sizes;
69-
return QueueInterface::Status::UNKNOWN_ERROR;
69+
return QueueInterface::Status::ALLOCATION_FAILED;
7070
}
7171
// Allocate max heap or clean-up
7272
bool created = this->m_handle.m_heap.create(depth);
7373
if (not created) {
7474
delete[] indices;
7575
delete[] sizes;
7676
delete[] data;
77-
return QueueInterface::Status::UNKNOWN_ERROR;
77+
return QueueInterface::Status::ALLOCATION_FAILED;
7878
}
7979
// Assign initial indices and sizes
8080
for (FwSizeType i = 0; i < depth; i++) {

Os/Models/Models.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,8 @@ static_assert(static_cast<Os::QueueStatus::T>(Os::Queue::Status::FULL) == Os::Qu
204204
"Queue status enums do not match");
205205
static_assert(static_cast<Os::QueueStatus::T>(Os::Queue::Status::UNKNOWN_ERROR) == Os::QueueStatus::T::UNKNOWN_ERROR,
206206
"Queue status enums do not match");
207+
static_assert(static_cast<Os::QueueStatus::T>(Os::Queue::Status::ALLOCATION_FAILED) == Os::QueueStatus::T::ALLOCATION_FAILED,
208+
"Queue status enums do not match");
207209

208210
// Check consistency of every constant in the Os::Queue::BlockingType enum
209211
static_assert(static_cast<Os::QueueBlockingType::T>(Os::Queue::BlockingType::BLOCKING) == Os::QueueBlockingType::T::BLOCKING,

Os/Models/Queue.fpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ module Os {
1616
INVALID_PRIORITY, @< invalid priority requested
1717
FULL, @< Queue was full when attempting to send a message
1818
NOT_SUPPORTED, @< Queue feature is not supported
19+
ALLOCATION_FAILED, @< required memory could not be allocated
1920
UNKNOWN_ERROR @< Unexpected error; can't match with returns
2021
}
2122

Os/Queue.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class QueueInterface {
3838
INVALID_PRIORITY, //!< invalid priority requested
3939
FULL, //!< Queue was full when attempting to send a message
4040
NOT_SUPPORTED, //!< Queue feature is not supported
41+
ALLOCATION_FAILED, //!< required memory could not be allocated
4142
UNKNOWN_ERROR //!< Unexpected error; can't match with returns
4243
};
4344

0 commit comments

Comments
 (0)