-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Fix Coverity issue: Initialize FlashIAP non-static member in constructor #11494
Conversation
@hugueskamba, thank you for your changes. |
To some extent, addressing some of these "uninitialized" warnings may add code size without actually changing anything - structures like that don't need to be initialised. So I'd be interested in making changes at the same time to potentially trim out some code to balance it. Here you could remove the empty destructor, and make the constructor inline by putting it in the class body (it could also be |
I get the following error if
|
Hmm,
should silence that error without really changing anything else about it. |
The code size is no different before my change, after my change or with the changes you are suggesting. I will leave as is because there is no meaningful benefits in making more changes. |
Are you sure you're building an image that actually uses FlashIAP somewhere? (And all toolchains?) I can believe the constructor changes might have no effect in some or even all toolchains, but I'm confident the destructor removal really must make a code size difference, at least the way FlashIAP is used in nvstore and kvstore. |
Good point...I am using k64f. How can I find out if a target uses |
It'll need to be a combo of a target and an application that uses its flash for storage. Sorry, I'm not really an expert. You'd want something like https://github.com/ARMmbed/mbed-os-example-kvstore for a real example. It might be easier just to have a dummy test program - add this to blinky:
That runs the construction/destruction cycle like kvstore does, albeit in a rather synthetic context. (Possibly too synthetic - it might overoptimise the new form, realising it doesn't even need to bother doing any construction. Might want to add a |
4389fed
to
8ea9aca
Compare
This force-push removes |
constexpr FlashIAP() : _flash(), _page_buf(nullptr) | ||
{ | ||
|
||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 !)
@hugueskamba what is the difference in code size before and after this PR with the dummy test program? |
Using Blinky with the changes suggested by Kevin in With the changes in this PR
Without the changes in this PR
|
Not sure I'd file this for 5.14.1 - there's a small chance of a binary compatibility glitch due to the eliminated out-of-line methods, and it's not really a bug fix. But if you're keen to get the 5.14 branch warning-free, it's fine. |
CI started |
Test run: FAILEDSummary: 1 of 11 test jobs failed Failed test jobs:
|
exporters restarted |
Description
Issue fixed:
FlashIAP.cpp:52 Non-static class member field _flash.dummy is not initialized in this constructor nor in any functions that it calls.
Pull request type
Reviewers
Release Notes