Skip to content

Fix Coverity issue: Initialize FlashIAP non-static member in constructor #11494

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions drivers/FlashIAP.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,10 @@ namespace mbed {
*/
class FlashIAP : private NonCopyable<FlashIAP> {
public:
FlashIAP();
~FlashIAP();
constexpr FlashIAP() : _flash(), _page_buf(nullptr)
{

}
Copy link
Contributor

@kjbracey kjbracey Sep 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just going to mention in passing that C++11 gives you another option here, which is kind of neater, but maybe less familiar.

You could do

// no need to declare constructor (it will be automatically constexpr)

private:
    flash_t _flash{};
    uint8_t *_page_buf = nullptr;

C++ Core Guidelines recommends that (see C.48 and C.49), but obviously that syntax is unfamiliar in our tree, what with us only just switching to C++11/14.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should first update our guidelines and then do this for the codebase (good mention !)


/** Initialize a flash IAP device
*
Expand Down
10 changes: 0 additions & 10 deletions drivers/source/FlashIAP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,6 @@ static inline bool is_aligned(uint32_t number, uint32_t alignment)
}
}

FlashIAP::FlashIAP() : _page_buf(nullptr)
{

}

FlashIAP::~FlashIAP()
{

}

int FlashIAP::init()
{
int ret = 0;
Expand Down
4 changes: 2 additions & 2 deletions platform/NonCopyable.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,11 @@ class NonCopyable {
/**
* Disallow construction of NonCopyable objects from outside of its hierarchy.
*/
NonCopyable() { }
NonCopyable() = default;
/**
* Disallow destruction of NonCopyable objects from outside of its hierarchy.
*/
~NonCopyable() { }
~NonCopyable() = default;

#if (!defined(MBED_DEBUG) && (MBED_CONF_PLATFORM_FORCE_NON_COPYABLE_ERROR == 0))
/**
Expand Down