Skip to content

Commit

Permalink
Fixing debug assert failure in WriteStringCopy
Browse files Browse the repository at this point in the history
The WriteStringCopy function was accessing string pointers without
setting up error handling correctly, triggering asserts in debug
builds.
  • Loading branch information
MSLaguana committed Jul 25, 2017
1 parent 3c659bb commit d463aae
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 @@ -4183,15 +4183,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 @@ -4203,7 +4202,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 d463aae

Please sign in to comment.