From 761a0c9bac4ba94e88eb285eecf88ca9665b5eab Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 4 Apr 2022 15:39:02 +0200 Subject: [PATCH 1/2] new pool ctor which only takes len --- src/fsfw/datapool/PoolEntry.cpp | 14 ++++++++++---- src/fsfw/datapool/PoolEntry.h | 5 ++++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/fsfw/datapool/PoolEntry.cpp b/src/fsfw/datapool/PoolEntry.cpp index fd110e6c..d8e1d634 100644 --- a/src/fsfw/datapool/PoolEntry.cpp +++ b/src/fsfw/datapool/PoolEntry.cpp @@ -7,13 +7,19 @@ #include "fsfw/serviceinterface/ServiceInterface.h" template -PoolEntry::PoolEntry(std::initializer_list initValue, bool setValid) - : length(static_cast(initValue.size())), valid(setValid) { +PoolEntry::PoolEntry(uint8_t len, bool setValid): length(len), valid(setValid) { this->address = new T[this->length]; - if (initValue.size() == 0) { + std::memset(this->address, 0, this->getByteSize()); +} + +template +PoolEntry::PoolEntry(std::initializer_list initValues, bool setValid) + : length(static_cast(initValues.size())), valid(setValid) { + this->address = new T[this->length]; + if (initValues.size() == 0) { std::memset(this->address, 0, this->getByteSize()); } else { - std::copy(initValue.begin(), initValue.end(), this->address); + std::copy(initValues.begin(), initValues.end(), this->address); } } diff --git a/src/fsfw/datapool/PoolEntry.h b/src/fsfw/datapool/PoolEntry.h index d3d80f09..8bf9a41c 100644 --- a/src/fsfw/datapool/PoolEntry.h +++ b/src/fsfw/datapool/PoolEntry.h @@ -33,6 +33,9 @@ class PoolEntry : public PoolEntryIF { "instead! The ECSS standard defines a boolean as a one bit " "field. Therefore it is preferred to store a boolean as an " "uint8_t"); + + PoolEntry(uint8_t len = 1, bool setValid = false); + /** * @brief In the classe's constructor, space is allocated on the heap and * potential initialization values are copied to that space. @@ -49,7 +52,7 @@ class PoolEntry : public PoolEntryIF { * @param setValid * Sets the initialization flag. It is invalid by default. */ - PoolEntry(std::initializer_list initValue = {0}, bool setValid = false); + PoolEntry(std::initializer_list initValue, bool setValid = false); /** * @brief In the classe's constructor, space is allocated on the heap and From e4c6a69f776cd8056985ce56ba6528bd842a1ea8 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 4 Apr 2022 15:44:03 +0200 Subject: [PATCH 2/2] this should also zero-init the pool entries --- src/fsfw/datapool/PoolEntry.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/fsfw/datapool/PoolEntry.cpp b/src/fsfw/datapool/PoolEntry.cpp index d8e1d634..7e922bcb 100644 --- a/src/fsfw/datapool/PoolEntry.cpp +++ b/src/fsfw/datapool/PoolEntry.cpp @@ -8,17 +8,15 @@ template PoolEntry::PoolEntry(uint8_t len, bool setValid): length(len), valid(setValid) { - this->address = new T[this->length]; + this->address = new T[this->length](); std::memset(this->address, 0, this->getByteSize()); } template PoolEntry::PoolEntry(std::initializer_list initValues, bool setValid) : length(static_cast(initValues.size())), valid(setValid) { - this->address = new T[this->length]; - if (initValues.size() == 0) { - std::memset(this->address, 0, this->getByteSize()); - } else { + this->address = new T[this->length](); + if (initValues.size() > 0) { std::copy(initValues.begin(), initValues.end(), this->address); } } @@ -26,11 +24,9 @@ PoolEntry::PoolEntry(std::initializer_list initValues, bool setValid) template PoolEntry::PoolEntry(T* initValue, uint8_t setLength, bool setValid) : length(setLength), valid(setValid) { - this->address = new T[this->length]; + this->address = new T[this->length](); if (initValue != nullptr) { std::memcpy(this->address, initValue, this->getByteSize()); - } else { - std::memset(this->address, 0, this->getByteSize()); } }