Skip to content
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

CPPCheck Team Bravo Set 50 #38716

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

CPPCheck Team Bravo Set 50 #38716

wants to merge 5 commits into from

Conversation

Despiix
Copy link
Collaborator

@Despiix Despiix commented Jan 28, 2025

Description of work

Summary of work

There is no associated issue.

Further detail of work

Set 50: http://172.16.111.171/suppressionSet.php?setid=50

To test:

Check if all of the issues in set 50 are fixed correctly


Reviewer

Please comment on the points listed below (full description).
Your comments will be used as part of the gatekeeper process, so please comment clearly on what you have checked during your review. If changes are made to the PR during the review process then your final comment will be the most important for gatekeepers. In this comment you should make it clear why any earlier review is still valid, or confirm that all requested changes have been addressed.

Code Review

  • Is the code of an acceptable quality?
  • Does the code conform to the coding standards?
  • Are the unit tests small and test the class in isolation?
  • If there is GUI work does it follow the GUI standards?
  • If there are changes in the release notes then do they describe the changes appropriately?
  • Do the release notes conform to the release notes guide?

Functional Tests

  • Do changes function as described? Add comments below that describe the tests performed?
  • Do the changes handle unexpected situations, e.g. bad input?
  • Has the relevant (user and developer) documentation been added/updated?

Does everything look good? Mark the review as Approve. A member of @mantidproject/gatekeepers will take care of it.

Gatekeeper

If you need to request changes to a PR then please add a comment and set the review status to "Request changes". This will stop the PR from showing up in the list for other gatekeepers.

@Despiix Despiix changed the title Mark LoadLiveData.h as override CPPCheck Despina Set 50 Jan 28, 2025
@Despiix Despiix marked this pull request as ready for review January 28, 2025 16:15
@Despiix Despiix added the Maintenance Unassigned issues to be addressed in the next maintenance period. label Jan 28, 2025
@Despiix Despiix changed the title CPPCheck Despina Set 50 CPPCheck Team Bravo Set 50 Jan 28, 2025
@sf1919 sf1919 added this to the Release 6.13 milestone Jan 29, 2025
@Despiix Despiix force-pushed the cpp-check-Set-50 branch 8 times, most recently from f41d0ff to 0dd88b4 Compare January 31, 2025 11:52
@jclarkeSTFC jclarkeSTFC self-assigned this Feb 3, 2025
Copy link
Contributor

@jclarkeSTFC jclarkeSTFC left a comment

Choose a reason for hiding this comment

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

You were a bit unlucky getting this set of Cppcheck suppressions to deal with, but looks pretty good, although I've made a few suggestions.

@@ -67,7 +69,7 @@ struct TCPStreamEventHeader {
static const uint32_t minor_version = 0; ///< reset to 0 in major version change, then incremented whenever
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd suggest deleting minor_version completely, since it seems to have not changed for at least 12 years, then can get rid of the suppression on line 62 as well.

Despiix and others added 5 commits February 4, 2025 15:21
plus invalidPointerCasting from int to double.
 TCPEventStreamDefs unsignedPositive was comparing an int to an uint32.
…in TCPEventStreamDefs.h

Suppressed some because they worked correctly. Explanations are written in comments above suppressions.

Co-authored-by: thomashampson <[email protected]>
Co-authored-by: Jonathan Haigh <[email protected]>
Change code based on review comments

Co-authored-by: James Clarke <[email protected]>
Copy link
Contributor

@jclarkeSTFC jclarkeSTFC left a comment

Choose a reason for hiding this comment

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

Needs a bit more refactoring to reduce code duplication, plus the logic in TCPEventStreamDefs.h should not change from what it was before.

/// layout of this or further packets changes in a backward compatible
/// way
static const uint32_t current_version = (major_version << 16) | minor_version; ///< starts at 1, then incremented
static const uint32_t current_version = (major_version << 16); ///< starts at 1, then incremented
Copy link
Contributor

Choose a reason for hiding this comment

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

minorVersion shouldn't be deleted, because that can change with version, you only need to delete the static minor_version, then the check becomes

minorVersion() >= 0 && type != InvalidStream;

At the moment the type check has gone as well, but we want to maintain existing behaviour.

}

private:
double extractDouble(uint32_t index, uint32_t fieldOffset) const {
Copy link
Contributor

Choose a reason for hiding this comment

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

You've got the same code in two separate functions in different classes, both called extractDouble, the idea is to have the code in one place, because otherwise you may as well just put the duplicate code inline in both places. Because the method is needed in different classes you could either add a static method to the file, or put it on the common base class, Packet, (second option sounds better to me).

double value() const { return *reinterpret_cast<const double *>(&m_fields[3]); }
double value() const {
double result;
std::memcpy(&result, &m_fields[3], sizeof(double));
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be using the new extractDouble function you're adding.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Maintenance Unassigned issues to be addressed in the next maintenance period.
Projects
Status: Ready for Review
Development

Successfully merging this pull request may close these issues.

3 participants