Skip to content

Commit

Permalink
[MERGE #3432 @MSLaguana] Fixing debug assert failure in WriteStringCopy
Browse files Browse the repository at this point in the history
Merge pull request #3432 from MSLaguana:fixStringCopyErrorChecking

The WriteStringCopy function was accessing string pointers without
setting up error handling correctly, triggering asserts in debug
builds.
  • Loading branch information
MSLaguana committed Jul 26, 2017
2 parents 78b3208 + d463aae commit 55a0eb1
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions lib/Jsrt/Jsrt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4194,15 +4194,14 @@ JsErrorCode WriteStringCopy(
*written = 0; // init to 0 for default
}

if (!Js::JavascriptString::Is(value))
const char16* str = nullptr;
size_t strLength = 0;
JsErrorCode errorCode = JsStringToPointer(value, &str, &strLength);
if (errorCode != JsNoError)
{
return JsErrorInvalidArgument;
return errorCode;
}

Js::JavascriptString *jsString = Js::JavascriptString::FromVar(value);
const char16* str = jsString->GetSz();
size_t strLength = jsString->GetLength();

if (start < 0 || (size_t)start > strLength)
{
return JsErrorInvalidArgument; // start out of range, no chars written
Expand All @@ -4214,7 +4213,7 @@ JsErrorCode WriteStringCopy(
return JsNoError; // no chars written
}

JsErrorCode errorCode = copyFunc(str + start, count, written);
errorCode = copyFunc(str + start, count, written);
if (errorCode != JsNoError)
{
return errorCode;
Expand Down

0 comments on commit 55a0eb1

Please sign in to comment.