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

src: fix compiler warning in udp_wrap.cc #15402

Closed
wants to merge 1 commit into from

Conversation

danbev
Copy link
Contributor

@danbev danbev commented Sep 14, 2017

Currently the following compiler warning is generated:

1 warning generated.
../src/udp_wrap.cc:238:12: warning: comparison of integers of different
signs: 'int' and 'uint32_t' (aka 'unsigned int') [-Wsign-compare]
  if (size != args[0].As<Uint32>()->Value()) {
      ~~~~ ^  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.

This commit changes the check to see that the Uint32 value does not
exceed the max int size instead of first casting and then comparing.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows commit guidelines
Affected core subsystem(s)

src

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. dgram Issues and PRs related to the dgram subsystem / UDP. labels Sep 14, 2017
src/udp_wrap.cc Outdated
@@ -233,16 +233,17 @@ void UDPWrap::BufferSize(const FunctionCallbackInfo<Value>& args) {

CHECK(args[0]->IsUint32());
CHECK(args[1]->IsUint32());
int size = static_cast<int>(args[0].As<Uint32>()->Value());
unsigned int u_size = static_cast<int>(args[0].As<Uint32>()->Value());
Copy link
Contributor

Choose a reason for hiding this comment

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

Better to use uint32_t?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Much better, will update now. Thanks!

@danbev danbev force-pushed the udp_wrap_compiler_warning branch from 282baf3 to c91f5ec Compare September 14, 2017 06:52
@danbev
Copy link
Contributor Author

danbev commented Sep 14, 2017

@danbev danbev force-pushed the udp_wrap_compiler_warning branch from c91f5ec to a1c2c81 Compare September 14, 2017 07:34
@danbev
Copy link
Contributor Author

danbev commented Sep 14, 2017

src/udp_wrap.cc Outdated
@@ -233,16 +233,17 @@ void UDPWrap::BufferSize(const FunctionCallbackInfo<Value>& args) {

CHECK(args[0]->IsUint32());
CHECK(args[1]->IsUint32());
int size = static_cast<int>(args[0].As<Uint32>()->Value());
uint32_t u_size = static_cast<int>(args[0].As<Uint32>()->Value());
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't this be static_cast<uint32_t> ?

Copy link
Member

Choose a reason for hiding this comment

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

actually, Uint32::Value() returns a uint32_t already so you can remove the cast

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@targos Thanks!

I was just focusing on the compiler warning and not giving proper attention to the code I'm afraid. I think it was correct to have the cast to int as this is then checked to make sure that the value can fit into an int before passing it along to uv_recv_buffer_size or uv_send_buffer_size. Otherwise it will never detect such a situation.

@danbev danbev force-pushed the udp_wrap_compiler_warning branch from a1c2c81 to 115989a Compare September 15, 2017 05:21
src/udp_wrap.cc Outdated

if (size != args[0].As<Uint32>()->Value()) {
if (args[0].As<Uint32>()->Value() > std::numeric_limits<int>::max()) {
Copy link
Member

Choose a reason for hiding this comment

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

Thanks!

There is a IsInt32() function, https://cs.chromium.org/chromium/src/v8/src/api.cc?q=IsUint32&sq=package:chromium&l=3694.

If you want, we could replace the > check with IsInt32(). But I'm also fine with landing as is, as it's correct and gets rid of the compiler warning.

Copy link
Member

Choose a reason for hiding this comment

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

There is a bit too much typecasting to my taste. I'd probably assign it to a uint32_t, do the range check and only then assign it to an int. IsInt32() would work too since the CHECK(args[0]->IsUint32()) a few lines up establishes that it's >= 0.

Aside: the second argument is really just a bool in disguise. The logic in lib/dgram.js could be simplified to self._handle.bufferSize(size, buffer === 'recv') if the code here was updated to expect a bool.

Aside aside: since this is new code, it should have been written to use the Value() overloads that take a Local<Context>. Oh well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@fhinkel Nice, I was not aware of that. I'll update the PR. Thanks!

@bnoordhuis I'd be happy to take a closer look at this, but perhaps as a separate PR?

Currently the following compiler warning is generated:
1 warning generated.
../src/udp_wrap.cc:238:12: warning: comparison of integers of different
signs: 'int' and 'uint32_t' (aka 'unsigned int') [-Wsign-compare]
  if (size != args[0].As<Uint32>()->Value()) {
      ~~~~ ^  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.

This commit changes the check to see that the Uint32 value does not
exceed the max int size instead of first casting and then comparing.
@danbev danbev force-pushed the udp_wrap_compiler_warning branch from 115989a to ff211e9 Compare September 17, 2017 10:06
@danbev
Copy link
Contributor Author

danbev commented Sep 20, 2017

@danbev
Copy link
Contributor Author

danbev commented Sep 20, 2017

test/aix failure looks unrelated

console output:

not ok 1686 inspector/test-stop-profile-after-done # TODO : Fix flaky test
  ---
  duration_ms: 0.791
  severity: flaky
  stack: |-
    [test] Connecting to a child Node process
    [test] Testing /json/list
    [err] Debugger listening on ws://127.0.0.1:55055/85359bfe-2a33-4295-936c-616bbf936f31
    [err] For help see https://nodejs.org/en/docs/inspector
    [err] 
    [out] {}
    [out] 
    [out] {}
    [out] 
    [out] {}
    [out] 
    [out] {}
    [out] 
    [out] {}
    [out] 
    [out] {}
    [out] 
    [out] {}
    [out] 
    [out] {}
    [out] 
    [out] {}
    [out] 
    [out] {}
    [out] 
    [out] {}
    [out] 
    { Error: connect ECONNREFUSED 127.0.0.1:55055
        at Object._errnoException (util.js:1018:13)
        at _exceptionWithHostPort (util.js:1039:20)
        at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1179:14)
      errno: 'ECONNREFUSED',
      code: 'ECONNREFUSED',
      syscall: 'connect',
      address: '127.0.0.1',
      port: 55055 }
    1
  ...
test/arm-fanned failure looks unrelated

console output:

+ git clean -fdx
warning: failed to remove out/
Removing out/
Build step 'Execute shell' marked build as failure
TAP Reports Processing: START
Looking for TAP results report in workspace using pattern: *.tap
Did not find any matching files. Setting build result to FAILURE.
Checking ^not ok
Jenkins Text Finder: File set '*.tap' is empty
Notifying upstream projects of job completion
Finished: FAILURE

danbev added a commit to danbev/node that referenced this pull request Sep 20, 2017
Currently the following compiler warning is generated:
1 warning generated.
../src/udp_wrap.cc:238:12: warning: comparison of integers of different
signs: 'int' and 'uint32_t' (aka 'unsigned int') [-Wsign-compare]
  if (size != args[0].As<Uint32>()->Value()) {
      ~~~~ ^  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.

This commit changes the check to see that the Uint32 value does not
exceed the max int size instead of first casting and then comparing.

PR-URL: nodejs#15402
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
@danbev
Copy link
Contributor Author

danbev commented Sep 20, 2017

Landed in 87bddda.

@targos @fhinkel Thanks!

@danbev danbev closed this Sep 20, 2017
@danbev danbev deleted the udp_wrap_compiler_warning branch September 20, 2017 14:00
@jasnell jasnell mentioned this pull request Sep 20, 2017
4 tasks
@jasnell
Copy link
Member

jasnell commented Sep 20, 2017

This does not land cleanly in v8.x as it depends on #13623 and should be backported along with that one.

Qard pushed a commit to Qard/ayo that referenced this pull request Sep 21, 2017
Currently the following compiler warning is generated:
1 warning generated.
../src/udp_wrap.cc:238:12: warning: comparison of integers of different
signs: 'int' and 'uint32_t' (aka 'unsigned int') [-Wsign-compare]
  if (size != args[0].As<Uint32>()->Value()) {
      ~~~~ ^  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.

This commit changes the check to see that the Uint32 value does not
exceed the max int size instead of first casting and then comparing.

PR-URL: nodejs/node#15402
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
Qard pushed a commit to Qard/ayo that referenced this pull request Sep 21, 2017
Currently the following compiler warning is generated:
1 warning generated.
../src/udp_wrap.cc:238:12: warning: comparison of integers of different
signs: 'int' and 'uint32_t' (aka 'unsigned int') [-Wsign-compare]
  if (size != args[0].As<Uint32>()->Value()) {
      ~~~~ ^  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.

This commit changes the check to see that the Uint32 value does not
exceed the max int size instead of first casting and then comparing.

PR-URL: nodejs/node#15402
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
MylesBorins pushed a commit that referenced this pull request Sep 28, 2017
Currently the following compiler warning is generated:
1 warning generated.
../src/udp_wrap.cc:238:12: warning: comparison of integers of different
signs: 'int' and 'uint32_t' (aka 'unsigned int') [-Wsign-compare]
  if (size != args[0].As<Uint32>()->Value()) {
      ~~~~ ^  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.

This commit changes the check to see that the Uint32 value does not
exceed the max int size instead of first casting and then comparing.

PR-URL: #15402
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
MylesBorins pushed a commit that referenced this pull request Sep 29, 2017
Currently the following compiler warning is generated:
1 warning generated.
../src/udp_wrap.cc:238:12: warning: comparison of integers of different
signs: 'int' and 'uint32_t' (aka 'unsigned int') [-Wsign-compare]
  if (size != args[0].As<Uint32>()->Value()) {
      ~~~~ ^  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.

This commit changes the check to see that the Uint32 value does not
exceed the max int size instead of first casting and then comparing.

PR-URL: #15402
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
MylesBorins pushed a commit that referenced this pull request Oct 3, 2017
Currently the following compiler warning is generated:
1 warning generated.
../src/udp_wrap.cc:238:12: warning: comparison of integers of different
signs: 'int' and 'uint32_t' (aka 'unsigned int') [-Wsign-compare]
  if (size != args[0].As<Uint32>()->Value()) {
      ~~~~ ^  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.

This commit changes the check to see that the Uint32 value does not
exceed the max int size instead of first casting and then comparing.

PR-URL: #15402
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
@MylesBorins MylesBorins mentioned this pull request Oct 3, 2017
MylesBorins pushed a commit that referenced this pull request Oct 3, 2017
Currently the following compiler warning is generated:
1 warning generated.
../src/udp_wrap.cc:238:12: warning: comparison of integers of different
signs: 'int' and 'uint32_t' (aka 'unsigned int') [-Wsign-compare]
  if (size != args[0].As<Uint32>()->Value()) {
      ~~~~ ^  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.

This commit changes the check to see that the Uint32 value does not
exceed the max int size instead of first casting and then comparing.

PR-URL: #15402
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
MylesBorins pushed a commit that referenced this pull request Oct 11, 2017
Currently the following compiler warning is generated:
1 warning generated.
../src/udp_wrap.cc:238:12: warning: comparison of integers of different
signs: 'int' and 'uint32_t' (aka 'unsigned int') [-Wsign-compare]
  if (size != args[0].As<Uint32>()->Value()) {
      ~~~~ ^  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.

This commit changes the check to see that the Uint32 value does not
exceed the max int size instead of first casting and then comparing.

PR-URL: #15402
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
@MylesBorins
Copy link
Contributor

setting as dont-land-v6.x as the commit this is based on is Semver-Minor and has not landed in v6.x. Please lmk if you think we should reconsider

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ Issues and PRs that require attention from people who are familiar with C++. dgram Issues and PRs related to the dgram subsystem / UDP.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants