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 'Wconversion' warns: casting ints and check tcp endpoints #216

Merged
merged 11 commits into from
Apr 2, 2024

Conversation

melvinhe
Copy link
Contributor

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

Describe your changes

Maintaining long value returned by 'strtol' and casts to int if port in reasonable range. The changed files diffs below show the changes in #214 possibly due to resetting my local wconv_fix to remote.

This particular PR deals with the following -Wconversion warnings that pollutes the build logs:

/home/runner/work/blazingmq/blazingmq/src/groups/mwc/mwcio/mwcio_channel.cpp:66:50: warning: conversion from ‘BloombergLP::bslstl::StringRefImp<char>::size_type’ {aka ‘long unsigned int’} to ‘int’ may change value [-Wconversion]
   66 |                                        str.length())) {                       \
      |                                        ~~~~~~~~~~^~
/home/runner/work/blazingmq/blazingmq/src/groups/mwc/mwcio/mwcio_channel.cpp:71:5: note: in expansion of macro ‘CHECKVALUE’
   71 |     CHECKVALUE(LOW_WATERMARK)
      |     ^~~~~~~~~~
/home/runner/work/blazingmq/blazingmq/src/groups/mwc/mwcio/mwcio_channel.cpp:66:50: warning: conversion from ‘BloombergLP::bslstl::StringRefImp<char>::size_type’ {aka ‘long unsigned int’} to ‘int’ may change value [-Wconversion]
   66 |                                        str.length())) {                       \
      |                                        ~~~~~~~~~~^~
/home/runner/work/blazingmq/blazingmq/src/groups/mwc/mwcio/mwcio_channel.cpp:72:5: note: in expansion of macro ‘CHECKVALUE’
   72 |     CHECKVALUE(HIGH_WATERMARK)
      |     ^~~~~~~~~~
/home/runner/work/blazingmq/blazingmq/src/groups/mwc/mwcio/mwcio_tcpendpoint.cpp:93:25: warning: conversion from ‘long int’ to ‘int’ may change value [-Wconversion]
   93 |     d_port = bsl::strtol(uri.c_str() + colon + 1, 0, 10);
      |              ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/runner/work/blazingmq/blazingmq/src/groups/mwc/mwcio/mwcio_tcpendpoint.cpp: In member function ‘void BloombergLP::mwcio::TCPEndpoint::fromUriRaw(const string&)’:
/home/runner/work/blazingmq/blazingmq/src/groups/mwc/mwcio/mwcio_tcpendpoint.cpp:114:25: warning: conversion from ‘long int’ to ‘int’ may change value [-Wconversion]
  114 |     d_port = bsl::strtol(uri.c_str() + separator + 1, 0, 10);

Testing performed
N/A

Additional context
Currently only checks that 'temp_port' is within reasonable INT range rather than being more fine grained regarding valid tcp port values. This is likely fine though as we previously did not do a fine-grained valid port checking here.

@melvinhe melvinhe requested a review from a team as a code owner March 15, 2024 04:00
@678098 678098 self-assigned this Mar 19, 2024
@678098 678098 self-requested a review March 19, 2024 12:02
Copy link
Collaborator

@678098 678098 left a comment

Choose a reason for hiding this comment

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

Hi @melvinhe! Thank you for the PR! The comments here are more complex since the changes are less trivial

src/groups/mwc/mwcio/mwcio_tcpendpoint.cpp Outdated Show resolved Hide resolved
src/groups/mwc/mwcio/mwcio_tcpendpoint.cpp Outdated Show resolved Hide resolved
src/groups/mwc/mwcio/mwcio_tcpendpoint.cpp Outdated Show resolved Hide resolved
src/groups/mwc/mwcio/mwcio_tcpendpoint.cpp Outdated Show resolved Hide resolved
src/groups/mwc/mwcio/mwcio_tcpendpoint.cpp Outdated Show resolved Hide resolved
src/groups/mwc/mwcio/mwcio_tcpendpoint.cpp Outdated Show resolved Hide resolved
src/groups/mwc/mwcio/mwcio_tcpendpoint.cpp Outdated Show resolved Hide resolved
src/groups/mwc/mwcio/mwcio_tcpendpoint.cpp Show resolved Hide resolved
@melvinhe
Copy link
Contributor Author

@678098 Thanks for the detailed feedback; this really helps me write cleaner/scalable code and become a better (open source) engineer.

I’ve updated your code suggestions in the most recent commit, which seems to be passing the test checks now. For future potential commits, I’ll just sync/fetch from main and create time stamped branches for each PR.

@melvinhe melvinhe requested a review from 678098 March 20, 2024 21:06
Copy link
Collaborator

@678098 678098 left a comment

Choose a reason for hiding this comment

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

Hi @melvinhe, sorry for the delay.
I prepared a couple of comments, I think we can apply them and merge the PR soon.

src/groups/mwc/mwcio/mwcio_tcpendpoint.cpp Outdated Show resolved Hide resolved
src/groups/mwc/mwcio/mwcio_tcpendpoint.cpp Outdated Show resolved Hide resolved
@melvinhe
Copy link
Contributor Author

Hi @678098, changes for handling '0' port values have been applied. Passing all tests except build for macosx_arm64, which seem to be unrelated to the committed code changes.

@678098
Copy link
Collaborator

678098 commented Mar 30, 2024

Hi @678098, changes for handling '0' port values have been applied. Passing all tests except build for macosx_arm64, which seem to be unrelated to the committed code changes.

Thank you @melvinhe! Will merge this branch once the CI fix is merged

@678098 678098 merged commit bbc0683 into bloomberg:main Apr 2, 2024
10 checks passed
syuzvinsky pushed a commit to syuzvinsky/blazingmq that referenced this pull request Apr 4, 2024
…erg#216)


Signed-off-by: Melvin He <[email protected]>
Co-authored-by: Patrick M. Niedzielski <[email protected]>
Co-authored-by: Evgeny Malygin <[email protected]>
alexander-e1off pushed a commit to alexander-e1off/blazingmq that referenced this pull request Oct 24, 2024
…erg#216)


Signed-off-by: Melvin He <[email protected]>
Co-authored-by: Patrick M. Niedzielski <[email protected]>
Co-authored-by: Evgeny Malygin <[email protected]>
alexander-e1off pushed a commit to alexander-e1off/blazingmq that referenced this pull request Oct 24, 2024
…erg#216)


Signed-off-by: Melvin He <[email protected]>
Co-authored-by: Patrick M. Niedzielski <[email protected]>
Co-authored-by: Evgeny Malygin <[email protected]>
alexander-e1off pushed a commit to alexander-e1off/blazingmq that referenced this pull request Oct 24, 2024
…erg#216)


Signed-off-by: Melvin He <[email protected]>
Co-authored-by: Patrick M. Niedzielski <[email protected]>
Co-authored-by: Evgeny Malygin <[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.

2 participants