diff options
| author | Patrick Venture <venture@google.com> | 2018-10-21 13:03:01 -0700 |
|---|---|---|
| committer | Patrick Venture <venture@google.com> | 2018-10-30 08:28:31 -0700 |
| commit | f0f1ab9f94c58cdddae3c5036c1cbc6a95a7016d (patch) | |
| tree | ab1a44642c9024e0945c70b6597ff987121d8674 | |
| parent | 740d8c00d3947dccb08611545f49da2bc5094189 (diff) | |
| download | ipmi-fru-parser-f0f1ab9f94c58cdddae3c5036c1cbc6a95a7016d.tar.gz ipmi-fru-parser-f0f1ab9f94c58cdddae3c5036c1cbc6a95a7016d.zip | |
IPMIFruArea: use vector instead of raw byte pointer
Use vector of bytes instead of raw byte pointer.
Change-Id: I20a2beec3cbbc44c8cc3a48cefd73f3f27bdcc8f
Signed-off-by: Patrick Venture <venture@google.com>
| -rw-r--r-- | fru_area.cpp | 10 | ||||
| -rw-r--r-- | fru_area.hpp | 11 |
2 files changed, 6 insertions, 15 deletions
diff --git a/fru_area.cpp b/fru_area.cpp index b5d8960..45d4008 100644 --- a/fru_area.cpp +++ b/fru_area.cpp @@ -49,9 +49,8 @@ IPMIFruArea::IPMIFruArea(const uint8_t fruID, const ipmi_fru_area_type type, //----------------------------------------------------- void IPMIFruArea::setData(const uint8_t* value, const size_t length) { - len = length; - data = new uint8_t[len]; - std::memcpy(data, value, len); + data.reserve(length); // pre-allocate the space. + data.insert(data.begin(), value, value + length); } //----------------------------------------------------- @@ -70,9 +69,4 @@ void IPMIFruArea::updateDbusPaths(const char* bus, const char* path, //------------------- IPMIFruArea::~IPMIFruArea() { - if (data != NULL) - { - delete[] data; - data = NULL; - } } diff --git a/fru_area.hpp b/fru_area.hpp index 28d50be..5294be2 100644 --- a/fru_area.hpp +++ b/fru_area.hpp @@ -38,7 +38,7 @@ class IPMIFruArea // Returns the length. size_t getLength() const { - return len; + return data.size(); } // Returns the type of the current fru area @@ -72,9 +72,9 @@ class IPMIFruArea } // Returns the data portion - inline uint8_t* getData() const + inline const uint8_t* getData() const { - return data; + return data.data(); } // Accepts a pointer to data and sets it in the object. @@ -93,9 +93,6 @@ class IPMIFruArea // Name of the fru area. ( BOARD/CHASSIS/PRODUCT ) std::string name; - // Length of a specific fru area. - size_t len = 0; - // Special bit for BMC readable eeprom only. bool bmcOnlyFru = false; @@ -106,7 +103,7 @@ class IPMIFruArea bool isValid = false; // Actual area data. - uint8_t* data = nullptr; + std::vector<uint8_t> data; // fru inventory dbus name std::string busName; |

