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

Fix: bmqp protocol Wconv warns #257

Merged
merged 12 commits into from
May 13, 2024

Conversation

melvinhe
Copy link
Contributor

@melvinhe melvinhe commented Apr 21, 2024

*Issue number of the reported bug or feature request: #87 *

Describe your changes
This PR attempts to fix all current -Wconversion warnings caused by faulty error checks, data type inconsistencies, and potential overflow/truncation data loss in ‘bmqp_protocol.cpp‘ as well as associated header and test files.

It should also clear out over a dozen errors that lead to at least 100 ‘-Wconversion‘ warnings in the BlazingMQ build logs such as, but limited to, the following:

In file included from /home/runner/work/blazingmq/blazingmq/src/groups/bmq/bmqp/bmqp_protocol.t.cpp:30:
/home/runner/work/blazingmq/blazingmq/src/groups/bmq/bmqp/bmqp_protocol.t.cpp: In function ‘void test1_breathingTest()’:
/home/runner/work/blazingmq/blazingmq/src/groups/bmq/bmqp/bmqp_protocol.t.cpp:720:31: warning: conversion from ‘int’ to ‘unsigned char’ may change value [-Wconversion]
  720 |                       sh.flags(),
      |                       ~~~~~~~~^~
/home/runner/work/blazingmq/blazingmq/src/groups/mwc/mwctst/mwctst_testhelper.h:360:34: note: in definition of macro ‘ASSERT_EQ’
  360 |         _assertCompareEquals("", X, Y, #X, #Y, __FILE__, __LINE__);           \
      |                                  ^
      
/home/runner/work/blazingmq/blazingmq/src/groups/bmq/bmqp/bmqp_protocol.h: In member function ‘BloombergLP::bmqp::MessagePropertiesInfo::SchemaIdType BloombergLP::bmqp::MessagePropertiesInfo::schemaId() const’:
/home/runner/work/blazingmq/blazingmq/src/groups/bmq/bmqp/bmqp_protocol.h:3518:27: warning: conversion from ‘unsigned int’ to ‘BloombergLP::bmqp::MessagePropertiesInfo::SchemaIdType’ {aka ‘short unsigned int’} may change value [-Wconversion]
 3518 |     return d_schemaWireId >> 1;
      |            ~~~~~~~~~~~~~~~^~~~
/home/runner/work/blazingmq/blazingmq/src/groups/bmq/bmqp/bmqp_protocol.h: In constructor ‘BloombergLP::bmqp::RdaInfo::RdaInfo(unsigned int)’:
/home/runner/work/blazingmq/blazingmq/src/groups/bmq/bmqp/bmqp_protocol.h:3568:17: warning: conversion from ‘unsigned int’ to ‘unsigned char’ may change value [-Wconversion]
 3568 |     d_counter = internalRepresentation;
      |                 ^~~~~~~~~~~~~~~~~~~~~~
/home/runner/work/blazingmq/blazingmq/src/groups/bmq/bmqp/bmqp_protocol.h: In member function ‘BloombergLP::bmqp::RdaInfo& BloombergLP::bmqp::RdaInfo::setCounter(unsigned int)’:
/home/runner/work/blazingmq/blazingmq/src/groups/bmq/bmqp/bmqp_protocol.h:3603:19: warning: conversion from ‘unsigned int’ to ‘unsigned char’ may change value [-Wconversion]
 3603 |         d_counter += counter;
      |         ~~~~~~~~~~^~~~~~~~~~

/home/runner/work/blazingmq/blazingmq/src/groups/bmq/bmqp/bmqp_protocol.cpp:836:50: warning: conversion from ‘BloombergLP::bslstl::StringRefImp<char>::size_type’ {aka ‘long unsigned int’} to ‘int’ may change value [-Wconversion]
  836 |                                        str.length())) {                       \
      |                                        ~~~~~~~~~~^~
/home/runner/work/blazingmq/blazingmq/src/groups/bmq/bmqp/bmqp_protocol.cpp:844:5: note: in expansion of macro ‘CHECKVALUE’
  844 |     CHECKVALUE(UNUSED4)
      |     ^~~~~~~~~~
/home/runner/work/blazingmq/blazingmq/src/groups/bmq/bmqp/bmqp_protocol.cpp: In static member function ‘static int BloombergLP::bmqp::StorageHeaderFlagUtil::fromString(std::ostream&, unsigned char*, const string&)’:
/home/runner/work/blazingmq/blazingmq/src/groups/bmq/bmqp/bmqp_protocol.cpp:912:18: warning: conversion from ‘int’ to ‘unsigned char’ may change value [-Wconversion]
  912 |             *out |= value;
      |             ~~~~~^~~~~~~~

Testing performed
Ran through the CI's unit, formatting, and integration tests.

Additional context

Mainly casting to fix data type inconsistencies in my first diffs for this PR to start with a solution that is least invasive. Several cases may need additions like a precondition check, adjusting function signature, or changing a data type, although most changes seem to be fine after further review. I also left a few individual comments on noteworthy diffs.

@melvinhe melvinhe requested a review from a team as a code owner April 21, 2024 17:12
@pniedzielski pniedzielski self-assigned this Apr 23, 2024
@pniedzielski pniedzielski self-requested a review April 23, 2024 14:37
@melvinhe
Copy link
Contributor Author

melvinhe commented Apr 25, 2024

@pniedzielski A lot of other functions and dependencies reference these 'bmqp_protocol' files. So these changes, after running these adjustments through the CI, surprisingly reduced over 8,000 occurrences of '-Wconversion' (from 12,238 down to 3,848)!

@678098
Copy link
Collaborator

678098 commented May 1, 2024

Nice catch @melvinhe!

@melvinhe
Copy link
Contributor Author

melvinhe commented May 6, 2024

@pniedzielski @678098 The changes in this commit seem to be fine and ready to merge soon, but feel free to take a look or sanity check. Most of these edits just deal with relatively simple data types, so the changes shouldn't really change core code functionality (other than removing a boat-load of build logs). Besides 'Tests / IT [multi/fsm_mode]' which seem to be due to recent ubuntu changes rather than this PR, the CI checks seem to pass.

@pniedzielski
Copy link
Collaborator

@melvinhe Some of these are a touch more involved, so I will look at it again tomorrow morning, but it looks good to me! Probably will be able to merge tomorrow.

Copy link
Collaborator

@pniedzielski pniedzielski left a comment

Choose a reason for hiding this comment

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

Thank you!

src/groups/bmq/bmqp/bmqp_protocol.h Outdated Show resolved Hide resolved
src/groups/bmq/bmqp/bmqp_protocol.h Outdated Show resolved Hide resolved
src/groups/bmq/bmqp/bmqp_protocol.t.cpp Outdated Show resolved Hide resolved
@pniedzielski pniedzielski self-requested a review May 8, 2024 17:04
Copy link
Collaborator

@pniedzielski pniedzielski left a comment

Choose a reason for hiding this comment

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

Sorry see above changes.

Copy link
Contributor Author

@melvinhe melvinhe left a comment

Choose a reason for hiding this comment

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

@pniedzielski confirming that CI checks passed after removing the nested cast. We're now down to 1,625 and 2,513 in docker & ubuntu builds respectively (from tens of thousands originally)!

@melvinhe melvinhe requested a review from pniedzielski May 10, 2024 16:59
Copy link
Contributor Author

@melvinhe melvinhe left a comment

Choose a reason for hiding this comment

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

Sorry see above changes.

Changes Resolved

@pniedzielski pniedzielski merged commit bb889ed into bloomberg:main May 13, 2024
13 checks passed
alexander-e1off pushed a commit to alexander-e1off/blazingmq that referenced this pull request Oct 24, 2024
Signed-off-by: Melvin He <[email protected]>
Signed-off-by: Patrick M. Niedzielski <[email protected]>
alexander-e1off pushed a commit to alexander-e1off/blazingmq that referenced this pull request Oct 24, 2024
Signed-off-by: Melvin He <[email protected]>
Signed-off-by: Patrick M. Niedzielski <[email protected]>
alexander-e1off pushed a commit to alexander-e1off/blazingmq that referenced this pull request Oct 24, 2024
Signed-off-by: Melvin He <[email protected]>
Signed-off-by: Patrick M. Niedzielski <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants