diff options
author | Lei YU <mine260309@gmail.com> | 2019-03-05 16:02:31 +0800 |
---|---|---|
committer | Lei YU <mine260309@gmail.com> | 2019-03-13 11:01:53 +0800 |
commit | 1db9adf37900c8503b3c9fa3fe39eef9406a30ff (patch) | |
tree | 7bc71b34d81babad764997c3c7620b88c9a2da31 | |
parent | 07830764398601b38d6dea9db269a7fb8efabbc8 (diff) | |
download | openpower-pnor-code-mgmt-1db9adf37900c8503b3c9fa3fe39eef9406a30ff.tar.gz openpower-pnor-code-mgmt-1db9adf37900c8503b3c9fa3fe39eef9406a30ff.zip |
Refactor: Fix issues found by cppcheck
Resolve several issues found by cppcheck:
[msl_verify.hpp:28]: (style) Class 'MinimumShipLevel' has a constructor with 1 argument that is not explicit.
[ubi/watch.hpp:21]: (warning) Assignment of function parameter has no effect outside the function. Did you forget dereferencing it?
[item_updater_main.cpp:22] -> [item_updater_main.cpp:49]: (style) Local variable rc shadows outer symbol
[serialize.cpp:19]: (performance) Function parameter 'versionId' should be passed by const reference.
[ubi/watch.hpp:43]: (style) Struct 'CustomFd' has a constructor with 1 argument that is not explicit.
[serialize.cpp:52]: (performance) Function parameter 'versionId' should be passed by const reference.
[serialize.cpp:116]: (performance) Function parameter 'versionId' should be passed by const reference.
[activation.cpp:115] -> [activation.cpp:152]: (style) Local variable mapperResponseMsg shadows outer symbol
[version.hpp:114]: (performance) Variable 'eraseCallback' is assigned in constructor body. Consider performing initialization in initialization list.
[image_verify.hpp:53]: (style) Struct 'CustomFd' has a constructor with 1 argument that is not explicit.
[ubi/item_updater_ubi.cpp:192]: (performance) Function parameter 'versionId' should be passed by const reference.
[ubi/item_updater_ubi.cpp:203]: (performance) Function parameter 'versionId' should be passed by const reference.
Tested: Verify the code compiles and cppcheck does not report the above
issues.
Change-Id: I096392a2a7a283fe198c9c29185125e61295e10f
Signed-off-by: Lei YU <mine260309@gmail.com>
-rw-r--r-- | activation.cpp | 2 | ||||
-rw-r--r-- | image_verify.hpp | 2 | ||||
-rw-r--r-- | item_updater_main.cpp | 2 | ||||
-rw-r--r-- | msl_verify.hpp | 2 | ||||
-rw-r--r-- | ubi/item_updater_ubi.cpp | 4 | ||||
-rw-r--r-- | ubi/item_updater_ubi.hpp | 4 | ||||
-rw-r--r-- | ubi/serialize.cpp | 6 | ||||
-rw-r--r-- | ubi/serialize.hpp | 6 | ||||
-rw-r--r-- | ubi/watch.hpp | 4 | ||||
-rw-r--r-- | version.hpp | 6 |
10 files changed, 18 insertions, 20 deletions
diff --git a/activation.cpp b/activation.cpp index ff4832627..1a64fcc27 100644 --- a/activation.cpp +++ b/activation.cpp @@ -143,7 +143,7 @@ void Activation::deleteImageManagerObject() deleteInterface, "Delete"); try { - auto mapperResponseMsg = bus.call(method); + mapperResponseMsg = bus.call(method); // Check that the bus call didn't result in an error if (mapperResponseMsg.is_method_error()) diff --git a/image_verify.hpp b/image_verify.hpp index 768182e79..31b5742c2 100644 --- a/image_verify.hpp +++ b/image_verify.hpp @@ -50,7 +50,7 @@ struct CustomFd * * @param[in] fd - File descriptor */ - CustomFd(int fd) : fd(fd) + explicit CustomFd(int fd) : fd(fd) { } diff --git a/item_updater_main.cpp b/item_updater_main.cpp index 9ba705bca..1792ad47b 100644 --- a/item_updater_main.cpp +++ b/item_updater_main.cpp @@ -46,7 +46,7 @@ int main(int argc, char* argv[]) &updater, std::placeholders::_1)); #endif bus.attach_event(loop, SD_EVENT_PRIORITY_NORMAL); - auto rc = sd_event_loop(loop); + rc = sd_event_loop(loop); if (rc < 0) { log<level::ERR>("Error occurred during the sd_event_loop", diff --git a/msl_verify.hpp b/msl_verify.hpp index 59f40173e..d3015d933 100644 --- a/msl_verify.hpp +++ b/msl_verify.hpp @@ -25,7 +25,7 @@ class MinimumShipLevel /** @brief Constructs MinimumShipLevel. * @param[in] minShipLevel - Minimum Ship Level string */ - MinimumShipLevel(const std::string& minShipLevel) : + explicit MinimumShipLevel(const std::string& minShipLevel) : minShipLevel(minShipLevel){}; /** @brief Verify if the current PNOR version meets the min ship level diff --git a/ubi/item_updater_ubi.cpp b/ubi/item_updater_ubi.cpp index cf8ffe0f9..83a514d7f 100644 --- a/ubi/item_updater_ubi.cpp +++ b/ubi/item_updater_ubi.cpp @@ -189,7 +189,7 @@ int ItemUpdaterUbi::validateSquashFSImage(const std::string& filePath) } } -void ItemUpdaterUbi::removeReadOnlyPartition(std::string versionId) +void ItemUpdaterUbi::removeReadOnlyPartition(const std::string& versionId) { auto serviceFile = "obmc-flash-bios-ubiumount-ro@" + versionId + ".service"; @@ -200,7 +200,7 @@ void ItemUpdaterUbi::removeReadOnlyPartition(std::string versionId) bus.call_noreply(method); } -void ItemUpdaterUbi::removeReadWritePartition(std::string versionId) +void ItemUpdaterUbi::removeReadWritePartition(const std::string& versionId) { auto serviceFile = "obmc-flash-bios-ubiumount-rw@" + versionId + ".service"; diff --git a/ubi/item_updater_ubi.hpp b/ubi/item_updater_ubi.hpp index fb6a6ca9c..183daac55 100644 --- a/ubi/item_updater_ubi.hpp +++ b/ubi/item_updater_ubi.hpp @@ -96,14 +96,14 @@ class ItemUpdaterUbi : public ItemUpdater * * @param[in] versionId - The id of the ro partition to remove. */ - void removeReadOnlyPartition(std::string versionId); + void removeReadOnlyPartition(const std::string& versionId); /** @brief Clears read write PNOR partition for * given Activation D-Bus object * * @param[in] versionId - The id of the rw partition to remove. */ - void removeReadWritePartition(std::string versionId); + void removeReadWritePartition(const std::string& versionId); /** @brief Clears preserved PNOR partition */ void removePreservedPartition(); diff --git a/ubi/serialize.cpp b/ubi/serialize.cpp index 7250a0050..a40925a6a 100644 --- a/ubi/serialize.cpp +++ b/ubi/serialize.cpp @@ -16,7 +16,7 @@ namespace updater namespace fs = std::experimental::filesystem; -void storeToFile(std::string versionId, uint8_t priority) +void storeToFile(const std::string& versionId, uint8_t priority) { auto bus = sdbusplus::bus::new_default(); @@ -49,7 +49,7 @@ void storeToFile(std::string versionId, uint8_t priority) bus.call_noreply(method); } -bool restoreFromFile(std::string versionId, uint8_t& priority) +bool restoreFromFile(const std::string& versionId, uint8_t& priority) { auto varPath = PERSIST_DIR + versionId; if (fs::exists(varPath)) @@ -113,7 +113,7 @@ bool restoreFromFile(std::string versionId, uint8_t& priority) return false; } -void removeFile(std::string versionId) +void removeFile(const std::string& versionId) { auto bus = sdbusplus::bus::new_default(); diff --git a/ubi/serialize.hpp b/ubi/serialize.hpp index e8860f32c..e5fefadbd 100644 --- a/ubi/serialize.hpp +++ b/ubi/serialize.hpp @@ -13,19 +13,19 @@ namespace updater * @param[in] versionId - The version for which to store information. * @param[in] priority - RedundancyPriority value for that version. */ -void storeToFile(std::string versionId, uint8_t priority); +void storeToFile(const std::string& versionId, uint8_t priority); /** @brief Serialization function - restores activation information from file * @param[in] versionId - The version for which to retrieve information. * @param[in] priority - RedundancyPriority pointer for that version. * @return true if restore was successful, false if not */ -bool restoreFromFile(std::string versionId, uint8_t& priority); +bool restoreFromFile(const std::string& versionId, uint8_t& priority); /** @brief Removes the serial file for a given version. * @param[in] versionId - The version for which to remove a file, if it exists. */ -void removeFile(std::string versionId); +void removeFile(const std::string& versionId); } // namespace updater } // namespace software diff --git a/ubi/watch.hpp b/ubi/watch.hpp index a04967e57..4d195a3e1 100644 --- a/ubi/watch.hpp +++ b/ubi/watch.hpp @@ -18,7 +18,7 @@ struct EventSourceDeleter { void operator()(sd_event_source* eventSource) const { - eventSource = sd_event_source_unref(eventSource); + sd_event_source_unref(eventSource); } }; using EventSourcePtr = std::unique_ptr<sd_event_source, EventSourceDeleter>; @@ -40,7 +40,7 @@ struct CustomFd * * @param[in] fd - File descriptor */ - CustomFd(int fd) : fd(fd) + explicit CustomFd(int fd) : fd(fd) { } diff --git a/version.hpp b/version.hpp index 831b20175..13f772fa0 100644 --- a/version.hpp +++ b/version.hpp @@ -99,8 +99,8 @@ class Version : public VersionInherit const std::string& versionString, VersionPurpose versionPurpose, const std::string& filePath, eraseFunc callback) : VersionInherit(bus, (objPath).c_str(), true), - bus(bus), objPath(objPath), parent(parent), versionId(versionId), - versionStr(versionString), + eraseCallback(callback), bus(bus), objPath(objPath), parent(parent), + versionId(versionId), versionStr(versionString), chassisStateSignals( bus, sdbusRule::type::signal() + sdbusRule::member("PropertiesChanged") + @@ -110,8 +110,6 @@ class Version : public VersionInherit std::bind(std::mem_fn(&Version::updateDeleteInterface), this, std::placeholders::_1)) { - // Bind erase method - eraseCallback = callback; // Set properties. purpose(versionPurpose); version(versionString); |