Skip to content

Fix simple SonarCloud issues#834

Merged
akuker merged 78 commits intodevelopfrom
fix_sonarcloud_issues
Sep 7, 2022
Merged

Fix simple SonarCloud issues#834
akuker merged 78 commits intodevelopfrom
fix_sonarcloud_issues

Conversation

@uweseimet
Copy link
Copy Markdown
Contributor

@uweseimet uweseimet commented Sep 4, 2022

This PR fixes SonarQube issues where the resolution appeared obvious to me and required no refactoring: Missing const, nullptr instead of NULL, empty methods, missing default cases etc.

There are a lot of remaining issues that require closer investigation, but also many that appear to be false positives, e.g. related to constness. This is amazing because with other languages false positives are extremely rare. This also needs further investigation.

@akuker I would like to ask for permission to change the SonarQube rule settings (for C++). I guess you have to configure this. Over time I intend to make the rules stricter, but for now I would just like to switch off the rule that complain about TODOs, for instance. We know that we have TODOs anyway, and the IDE already points them out.

@uweseimet uweseimet linked an issue Sep 4, 2022 that may be closed by this pull request
@uweseimet
Copy link
Copy Markdown
Contributor Author

uweseimet commented Sep 5, 2022

@akuker In order not to lose momentum I have already started a second round of addressing SonarCloud issues. There is a new fix_sonarcloud_issues2 (based on fix_sonarcloud_issues). In case you have not yet started reviewing fix_sonarcloud_issues I would like to merge fix_sonarcloud_issues2 into fix_sonarcloud_issues.
Just like with fix_sonarcloud_issues each change in fix_sonarcloud_issues2 usually only affects a single line.

With the right setup (Homebrew for protobuf and stdlog) rasctl now compiles and runs on macos (Intel), by the way.

@uweseimet
Copy link
Copy Markdown
Contributor Author

@akuker Regarding the emails with error reports I get, my impression is that they are in particular sent when something is committted while an action for a previous commit is still runing. Not absolutely sure, though.
Regarding this PR, the latest report (above) is outdated, and all builds for changes committed after that report was sent seem to have failed.
And one more thing: I suggest to configure away the coverage checks until supported. Currently quality gates fail because of 0% coverage even when there are no other issues. See #828 for such a report.

@uweseimet
Copy link
Copy Markdown
Contributor Author

@akuker Just figured out how to get the compile-time logs. The problem is a compile-time problem only visible with -O3. I will try to find a solution, till then I will put the PR back into draft status.

@uweseimet uweseimet marked this pull request as draft September 6, 2022 14:30
@uweseimet
Copy link
Copy Markdown
Contributor Author

Fixed the compile time error. It was related to a SonarQube (strcpy/strncpy) issue, which may have to be resolved later.

@uweseimet
Copy link
Copy Markdown
Contributor Author

Up to date SonarCloud results are now available for this PR.

@uweseimet uweseimet marked this pull request as ready for review September 6, 2022 14:46
{
const AbstractController *controller = FindController(id);
if (controller != nullptr) {
if (const auto controller = FindController(id); controller != nullptr) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could this be written like this?

if (FindController(id) != nullptr)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This would not work, because we need the controller in the next line. This is the complete context:

	if (const auto controller = FindController(id); controller != nullptr) {
		return controller->GetDeviceForLun(lun);
	}

	return nullptr;

@akuker
Copy link
Copy Markdown
Member

akuker commented Sep 7, 2022

Lots of changes! Thank you for looking into these, @uweseimet . Just a couple comments.

@uweseimet
Copy link
Copy Markdown
Contributor Author

uweseimet commented Sep 7, 2022

@akuker Thank you for reviewing. I am quite sure that from my side this PR is the last one with so many files being changed in a single PR. The other tickets (even those with major effort) would not affect essentially everything. I hope I am not making wrong promises ;-) And provided that there are not too many issues of this kind still being reported. I don't know why, but the issues reported by SonarLint within Eclipse do not always match those reported in the SonarCloud UI, even though SonarLint connects to the SonarCloud server and gets its settings from this server.

Some changes probably take getting used to, at least for me, because they are using C++ features I was not yet familiar with. When looking at the reasons why SonarCloud made these suggestions, and when looking at the C++ standard, they made a lot of sense. A lot of them reduce the danger of side effects. And some, like structured bindings, make the code much more explicit.

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Sep 7, 2022

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot D 4 Security Hotspots
Code Smell A 66 Code Smells

0.0% 0.0% Coverage
1.1% 1.1% Duplication

@akuker
Copy link
Copy Markdown
Member

akuker commented Sep 7, 2022

@akuker Thank you for reviewing. I am quite sure that from my side this PR is the last one with so many files being changed in a single PR. The other tickets (even those with major effort) would not affect essentially everything. I hope I am not making wrong promises ;-) And provided that there are not too many issues of this kind still being reported. I don't know why, but the issues reported by SonarLint within Eclipse do not always match those reported in the SonarCloud UI, even though SonarLint connects to the SonarCloud server and gets its settings from this server.

There might be settings we need to tweak in SonarCloud. I think I added you to the project, but I'm not sure if that gives you access to the settings or not.

Some changes probably take getting used to, at least for me, because they are using C++ features I was not yet familiar with. When looking at the reasons why SonarCloud made these suggestions, and when looking at the C++ standard, they made a lot of sense. A lot of them reduce the danger of side effects. And some, like structured bindings, make the code much more explicit.

These new features of C++ are new to me as well. I learned quite a bit from reviewing your changes, so thank you! :)

As a former Ada programmer, the auto keyword scares me..... Why would you want to use a variable if you don't explicitly define what its type is!! But, I can see the value in it.

@akuker akuker merged commit 05db0e4 into develop Sep 7, 2022
@akuker akuker deleted the fix_sonarcloud_issues branch September 7, 2022 14:38
@uweseimet
Copy link
Copy Markdown
Contributor Author

@akuker auto is similar to var/val etc. in other languages, and I do not use it everywhere. SonarCloud also does not propose to use it everywhere. It suggests to use it only when you can immediately see the type from the rvalue.

uweseimet added a commit that referenced this pull request Sep 7, 2022
* Fixing SonarCloud issues, first round

* Fixing SonarCLoud issues, next round

* Fixing SonarQube issues, next round

* Fixed warning

* Replaced empty constructors/destructors with = default;

* Fixed warning

* Replaced new

* Use constants instead of macros

* Use structured binding declarations

* Use init statements for if

* Use string views

* Use enum class, use using instead of typedef

* Fixed more SonarCloud warnings

* Replaced redundant/duplicate types with auto

* Devlared methods const

* Memory management update

* Fixed warning

* Added missing const

* Improved RaScsiResponse memory management

* Improved memory management

* Improved memory management

* Replaced macros by constants, removed unused constants

* Made member private

* Fixed warning

* Added comment

* Fixed shadowing warnings

* Cleanup

* Cleanup

* Cleanup

* Fixed shadowing warning

* Removed unused code

* Fixed more warnings

* Removed obsolete casts

* Fixed warnings

* Removed unused field

* Removed library not needed by rasctl

* Include cleanup

* Updated platform check for better compatibility

* Improved check for invalid option. This prevents rasctl to break on macos.

* Updated option check

* Fixed typo

* Added TODO

* Removed macro

* Scope update

* Replaced macro

* Added TODO, update memory management

* Fixed typo

* Replaced NULL by nullptr

* Use more structured bindings

* Added TODO

* Use calloc instead of mallco to not need memset

* Fixed warnings

* Fixed SonarQube initialization issues

* Fixed warning

* Cleaned up override/virtual/final

* Fixed warnings

* Constructor update

* Fixed tests

* Improved memory management

* Added missing const

* Added const

* Fixed two bugs reported by SonarCloud

* Fix SonarCloud hotspot

* Fixed memory management

* Memory management update

* Addressing hotspot by using strncpy

* Fixed SonarCloud issues

* Fixed SonarQube issues

* Added missing const

* Added const

* Added const

* Suppress false positive

* Added SonarQube suppressions for false positives

* Added suppresoin

* Fixed code smells

* Reverted changes that is a SonarQube issue, but caused problems with -O3

* Removed TODO based on review
@uweseimet
Copy link
Copy Markdown
Contributor Author

@akuker Regarding SonarCloud settings, being a project member is not sufficient. I would need to be able to create new quaiity profiles.

akuker added a commit that referenced this pull request Sep 8, 2022
* Added support for .hd1 (SCSI-1) image files

* Update c-cpp.yml

* Fixed unit test warnings

* Fixed wrong scan default default (must be 1, not -1)

* Updated max length check

* Removed file not present in develop branch

* Added unit test

* Added workflow configurations and README updates (#832)

* automated test try 1

* filter branches

* filter branches

* filter branches

* filter branches

* filter branches

* Configured build and test CI workflows

* enable for all branches

* Update README.md

* Update README.md

Co-authored-by: Tony Kuker <akuker@gmail.com>

* Fix simple SonarCloud issues (#834)

* Fixing SonarCloud issues, first round

* Fixing SonarCLoud issues, next round

* Fixing SonarQube issues, next round

* Fixed warning

* Replaced empty constructors/destructors with = default;

* Fixed warning

* Replaced new

* Use constants instead of macros

* Use structured binding declarations

* Use init statements for if

* Use string views

* Use enum class, use using instead of typedef

* Fixed more SonarCloud warnings

* Replaced redundant/duplicate types with auto

* Devlared methods const

* Memory management update

* Fixed warning

* Added missing const

* Improved RaScsiResponse memory management

* Improved memory management

* Improved memory management

* Replaced macros by constants, removed unused constants

* Made member private

* Fixed warning

* Added comment

* Fixed shadowing warnings

* Cleanup

* Cleanup

* Cleanup

* Fixed shadowing warning

* Removed unused code

* Fixed more warnings

* Removed obsolete casts

* Fixed warnings

* Removed unused field

* Removed library not needed by rasctl

* Include cleanup

* Updated platform check for better compatibility

* Improved check for invalid option. This prevents rasctl to break on macos.

* Updated option check

* Fixed typo

* Added TODO

* Removed macro

* Scope update

* Replaced macro

* Added TODO, update memory management

* Fixed typo

* Replaced NULL by nullptr

* Use more structured bindings

* Added TODO

* Use calloc instead of mallco to not need memset

* Fixed warnings

* Fixed SonarQube initialization issues

* Fixed warning

* Cleaned up override/virtual/final

* Fixed warnings

* Constructor update

* Fixed tests

* Improved memory management

* Added missing const

* Added const

* Fixed two bugs reported by SonarCloud

* Fix SonarCloud hotspot

* Fixed memory management

* Memory management update

* Addressing hotspot by using strncpy

* Fixed SonarCloud issues

* Fixed SonarQube issues

* Added missing const

* Added const

* Added const

* Suppress false positive

* Added SonarQube suppressions for false positives

* Added suppresoin

* Fixed code smells

* Reverted changes that is a SonarQube issue, but caused problems with -O3

* Removed TODO based on review

* Update c-cpp.yml

* Finalized merge

Co-authored-by: akuker <34318535+akuker@users.noreply.github.com>
Co-authored-by: Tony Kuker <akuker@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix SonarCloud issues that have a simple resolution

2 participants