Skip to content

Commit 6bec7ac

Browse files
committed
[MERGE #3588 @Krovatkin] Keep AutoString::length in sync w/ AutoString::data
Merge pull request #3588 from Krovatkin:autostr_len_fix This fix makes sure that `AutoString::length` and `AutoString::data` are in sync.
2 parents c68848a + d64b4ce commit 6bec7ac

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

bin/ch/stdafx.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,6 @@ class AutoString
201201
strValue = value;
202202
}
203203
int strLen = 0;
204-
size_t writtenLen = 0;
205204
size_t actualLen = 0;
206205
if (errorCode == JsNoError)
207206
{
@@ -210,19 +209,19 @@ class AutoString
210209
{
211210
// Assume ascii characters
212211
data = (char*)malloc((strLen + 1) * sizeof(char));
213-
errorCode = ChakraRTInterface::JsCopyString(strValue, data, strLen, &writtenLen, &actualLen);
212+
errorCode = ChakraRTInterface::JsCopyString(strValue, data, strLen, &length, &actualLen);
214213
if (errorCode == JsNoError)
215214
{
216215
// If non-ascii, take slow path
217-
if (writtenLen != actualLen)
216+
if (length != actualLen)
218217
{
219218
free(data);
220219
data = (char*)malloc((actualLen + 1) * sizeof(char));
221220

222-
errorCode = ChakraRTInterface::JsCopyString(strValue, data, actualLen + 1, &writtenLen, nullptr);
221+
errorCode = ChakraRTInterface::JsCopyString(strValue, data, actualLen + 1, &length, nullptr);
223222
if (errorCode == JsNoError)
224223
{
225-
AssertMsg(actualLen == writtenLen, "If you see this message.. There is something seriously wrong. Good Luck!");
224+
AssertMsg(actualLen == length, "If you see this message.. There is something seriously wrong. Good Luck!");
226225

227226
}
228227
}

0 commit comments

Comments
 (0)