-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
url: add return value to ToUnicode/ToAscii stubs #10893
Conversation
This fixes compilation errors like: node\src\node_url.cc(134) : error C4716: 'node::url::ToUnicode': must return a 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.
LGTM with a question for @jasnell
@@ -131,11 +131,13 @@ namespace url { | |||
static int ToUnicode(std::string* input, std::string* output) { | |||
output->reserve(input->length()); | |||
*output = input->c_str(); |
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.
@jasnell Is there any reason these functions can’t just be *output = *input; return 0;
?
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.
On that subject: as a slightly more wide-ranging cleanup, how about changing the return value from int to bool? It's already effectively boolean in that it returns either 0 or -1.
Also: it looks like both the ICU and non-ICU implementations should be able to use input->data()
instead of input->c_str()
. Avoids an unnecessary reallocation.
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.
Also: it looks like both the ICU and non-ICU implementations should be able to use
input->data()
instead ofinput->c_str()
. Avoids an unnecessary reallocation.
data()
is an alias for c_str()
since C++11. ;)
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.
I actually was going to do this, but *output = *input
is not equivalent to *output = input->c_str()
if the string contains null bytes so I decided to leave it alone. Seems like that is not a concern so I'll go ahead and change it.
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.
Good point – if I’m reading the code correctly, this should be *output = *input
? At least for ToASCII
, there’s an explicit check for null bytes just below the call to it.
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.
Yeah, seems safe, I just wasn't sure of the original intent of *output = input->c_str()
.
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.
LGTM with the edits suggested by @bnoordhuis and @addaleax
@jasnell Review feedback addressed, please retrigger CI. Thanks! |
This fixes compilation errors like: node\src\node_url.cc(134) : error C4716: 'node::url::ToUnicode': must return a value PR-URL: #10893 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michal Zasso <targos@protonmail.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Landed in dcab88d |
This fixes compilation errors like: node\src\node_url.cc(134) : error C4716: 'node::url::ToUnicode': must return a value PR-URL: nodejs#10893 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michal Zasso <targos@protonmail.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com>
This fixes compilation errors like: node\src\node_url.cc(134) : error C4716: 'node::url::ToUnicode': must return a value PR-URL: nodejs#10893 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michal Zasso <targos@protonmail.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com>
This fixes compilation errors like: node\src\node_url.cc(134) : error C4716: 'node::url::ToUnicode': must return a value PR-URL: nodejs#10893 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michal Zasso <targos@protonmail.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com>
This fixes compilation errors like: node\src\node_url.cc(134) : error C4716: 'node::url::ToUnicode': must return a value PR-URL: nodejs#10893 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michal Zasso <targos@protonmail.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
url