-
Notifications
You must be signed in to change notification settings - Fork 30k
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
Conversation
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()); |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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!
282baf3
to
c91f5ec
Compare
c91f5ec
to
a1c2c81
Compare
Updated CI run: https://ci.nodejs.org/job/node-test-pull-request/10073/ |
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()); |
There was a problem hiding this comment.
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>
?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
a1c2c81
to
115989a
Compare
src/udp_wrap.cc
Outdated
|
||
if (size != args[0].As<Uint32>()->Value()) { | ||
if (args[0].As<Uint32>()->Value() > std::numeric_limits<int>::max()) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
115989a
to
ff211e9
Compare
test/aix failure looks unrelatednot 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+ 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 |
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>
This does not land cleanly in v8.x as it depends on #13623 and should be backported along with that one. |
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>
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>
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>
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>
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>
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>
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>
setting as |
Currently the following compiler warning is 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), orvcbuild test
(Windows) passesAffected core subsystem(s)
src