Bug 1588810 - Fix ctypes UnicodeToNative callback to not assume null-terminated strings. r=bzbarsky

Bug 1586683 replaced the JS_FlattenString in the caller with JS_EnsureLinearString but
I wasn't aware of the nsDependentString vs nsDependentSubstring distinction.

This fixes assertion failures when starting the browser with non-null-terminated
JS strings.

Differential Revision: https://phabricator.services.mozilla.com/D49297

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Jan de Mooij 2019-10-16 06:13:07 +00:00
parent 9d573b660f
commit 026691dc76
2 changed files with 2 additions and 2 deletions

View File

@ -24,7 +24,7 @@ namespace {
char* UnicodeToNative(JSContext* aCx, const char16_t* aSource,
size_t aSourceLen) {
nsDependentString unicode(aSource, aSourceLen);
nsDependentSubstring unicode(aSource, aSourceLen);
nsAutoCString native;
if (NS_FAILED(NS_CopyUnicodeToNative(unicode, native))) {

View File

@ -20,7 +20,7 @@ namespace ctypes {
static char* UnicodeToNative(JSContext* cx, const char16_t* source,
size_t slen) {
nsAutoCString native;
nsDependentString unicode(reinterpret_cast<const char16_t*>(source), slen);
nsDependentSubstring unicode(source, slen);
nsresult rv = NS_CopyUnicodeToNative(unicode, native);
if (NS_FAILED(rv)) {
JS_ReportErrorASCII(cx, "could not convert string to native charset");