JSIndexedRAMBundle: Don't read null bytes for scripts

Summary:
`JSIndexedRAMBundle` used to read scripts including the terminating null bytes. That worked on iOS, but not on Android, where we have an ascii-only optimization.
This changes that behavior to only read the actual script data excluding the terminal null.

Reviewed By: javache

Differential Revision: D4265374

fbshipit-source-id: 7e6f943666aee610d79939cef09b103305803c69
This commit is contained in:
David Aurelio 2016-12-03 02:18:59 -08:00 committed by Facebook Github Bot
parent 9c0ea77684
commit b1a23914fa
2 changed files with 5 additions and 6 deletions

View File

@ -33,10 +33,9 @@ JSIndexedRAMBundle::JSIndexedRAMBundle(const char *sourcePath) :
reinterpret_cast<char *>(m_table.data.get()), m_table.byteLength());
// read the startup code
m_startupCode =
std::make_unique<facebook::react::JSBigBufferString>(startupCodeSize);
m_startupCode = std::unique_ptr<JSBigBufferString>(new JSBigBufferString{startupCodeSize - 1});
readBundle(m_startupCode->data(), startupCodeSize);
readBundle(m_startupCode->data(), startupCodeSize - 1);
}
JSIndexedRAMBundle::Module JSIndexedRAMBundle::getModule(uint32_t moduleId) const {
@ -61,8 +60,8 @@ std::string JSIndexedRAMBundle::getModuleCode(const uint32_t id) const {
toString("Error loading module", id, "from RAM Bundle"));
}
std::string ret(moduleData->length, '\0');
readBundle(&ret.front(), length, m_baseOffset + littleEndianToHost(moduleData->offset));
std::string ret(length - 1, '\0');
readBundle(&ret.front(), length - 1, m_baseOffset + littleEndianToHost(moduleData->offset));
return ret;
}

View File

@ -40,7 +40,7 @@ private:
ModuleTable() : numEntries(0) {};
ModuleTable(size_t entries) :
numEntries(entries),
data(std::make_unique<ModuleData[]>(numEntries)) {};
data(std::unique_ptr<ModuleData[]>(new ModuleData[numEntries])) {};
size_t byteLength() const {
return numEntries * sizeof(ModuleData);
}