Skip to content

Conversation

@MSLaguana
Copy link
Contributor

A confusion between bytes and character count meant that JsCreateString
was creating strings that used twice as much space as they needed.

While I was at it, I also tried to clean up the types in Utf8Helper.h to make it more clear what the values referred to.

@MSLaguana MSLaguana requested a review from obastemur February 5, 2018 23:43
@obastemur
Copy link
Collaborator

A confusion between bytes and character count meant that JsCreateString was creating strings that used twice as much space as they needed.

Could you please point out the change that is justifying the description above?

@obastemur
Copy link
Collaborator

Found it; size_t cbDestString = (charCount + 1) * sizeof(WCHAR);

Good catch.

@obastemur
Copy link
Collaborator

CI errors are related to type casting.

LGTM

@MSLaguana
Copy link
Contributor Author

Ah yep, I see that I missed some usages in wabt when I tweaked the templating. I'll get that fixed tomorrow.

Copy link
Contributor

@sethbrenith sethbrenith left a comment

Choose a reason for hiding this comment

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

Great catch!

ScriptContext * scriptContext = library->GetScriptContext();
size_t cbDestString = (charCount + 1) * sizeof(WCHAR);
if ((CharCount)cbDestString < charCount) // overflow
if (charCount > MaxCharCount) // overflow
Copy link
Contributor

Choose a reason for hiding this comment

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

"overflow" comment might be out of date; I think it was referring to arithmetic overflow when computing (charCount + 1) * sizeof(WCHAR)

…ewFromCString

A confusion between bytes and character count meant that JsCreateString
was creating strings that used twice as much space as they needed.
@MSLaguana MSLaguana force-pushed the fixJsrtStringCreation branch from 652a2ff to 1492900 Compare February 6, 2018 16:57
@chakrabot chakrabot merged commit 1492900 into chakra-core:release/1.9 Feb 6, 2018
chakrabot pushed a commit that referenced this pull request Feb 6, 2018
…gWithPropertyStringPtr::NewFromCString

Merge pull request #4641 from MSLaguana:fixJsrtStringCreation

A confusion between bytes and character count meant that JsCreateString
was creating strings that used twice as much space as they needed.

While I was at it, I also tried to clean up the types in `Utf8Helper.h` to make it more clear what the values referred to.
@MSLaguana
Copy link
Contributor Author

Thanks for the reviews!

@MSLaguana MSLaguana deleted the fixJsrtStringCreation branch February 6, 2018 17:51
chakrabot pushed a commit that referenced this pull request Feb 6, 2018
… LiteralStringWithPropertyStringPtr::NewFromCString

Merge pull request #4641 from MSLaguana:fixJsrtStringCreation

A confusion between bytes and character count meant that JsCreateString
was creating strings that used twice as much space as they needed.

While I was at it, I also tried to clean up the types in `Utf8Helper.h` to make it more clear what the values referred to.
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.

4 participants