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 use of uninitialized variable #9280

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/node_i18n.cc
Original file line number Diff line number Diff line change
Expand Up @@ -519,14 +519,22 @@ static void GetStringWidth(const FunctionCallbackInfo<Value>& args) {
}

TwoByteValue value(env->isolate(), args[0]);
if (value.length() <= 1) {
Copy link
Member

Choose a reason for hiding this comment

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

This additional shortcut is wrong. See the CI failures (https://ci.nodejs.org/job/node-test-commit-osx/5807/nodes=osx1010/console).

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm about to go to bed so if you want to take this over, go ahead.

Copy link
Member

Choose a reason for hiding this comment

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

+1 ... I just went ahead and created a new PR. I'll close this one in favor of that and we can follow up there. Thank you @bnoordhuis !

uint32_t width = static_cast<uint32_t>(value.length());
return args.GetReturnValue().Set(width);
}

// reinterpret_cast is required by windows to compile
UChar* str = reinterpret_cast<UChar*>(*value);
static_assert(sizeof(*str) == sizeof(**value),
"(sizeof(*str) == sizeof(**value)");
UChar32 c;
UChar32 p;
size_t n = 0;
uint32_t width = 0;

while (n < value.length()) {
U16_NEXT(str, n, value.length(), c);
do {
p = c;
U16_NEXT(str, n, value.length(), c);
// Don't count individual emoji codepoints that occur within an
Expand All @@ -546,7 +554,8 @@ static void GetStringWidth(const FunctionCallbackInfo<Value>& args) {
continue;
}
width += GetColumnWidth(c, ambiguous_as_full_width);
}
} while (n < value.length());

args.GetReturnValue().Set(width);
}

Expand Down