Skip to content

Commit

Permalink
Bug 1333081 - Avoid using the STL in nsXPCOMGlue.cpp to avoid allocat…
Browse files Browse the repository at this point in the history
…or mismatch on Windows. r=froydnj

--HG--
extra : rebase_source : a65a5cf3d197d88799d24514c6d860b2e6c111ab
  • Loading branch information
glandium committed Jan 23, 2017
1 parent 575eb25 commit 713aafb
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions xpcom/glue/standalone/nsXPCOMGlue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
#include "nsCOMPtr.h"
#include <stdlib.h>
#include <stdio.h>
#include <string>

#include "mozilla/FileUtils.h"
#include "mozilla/Sprintf.h"
#include "mozilla/UniquePtrExtensions.h"

using namespace mozilla;

Expand Down Expand Up @@ -395,14 +395,17 @@ GetBootstrap(const char* aXPCOMFile)
return nullptr;
}

std::string file(aXPCOMFile);
size_t lastSlash = file.rfind(XPCOM_FILE_PATH_SEPARATOR[0]);
if (lastSlash == std::string::npos) {
char *lastSlash = strrchr(const_cast<char *>(aXPCOMFile), XPCOM_FILE_PATH_SEPARATOR[0]);
if (!lastSlash) {
return nullptr;
}
file.replace(lastSlash + 1, std::string::npos, XPCOM_DLL);
size_t base_len = size_t(lastSlash - aXPCOMFile) + 1;

if (NS_FAILED(XPCOMGlueLoad(file.c_str()))) {
UniqueFreePtr<char> file(reinterpret_cast<char*>(malloc(base_len + sizeof(XPCOM_DLL))));
memcpy(file.get(), aXPCOMFile, base_len);
memcpy(file.get() + base_len, XPCOM_DLL, sizeof(XPCOM_DLL));

if (NS_FAILED(XPCOMGlueLoad(file.get()))) {
return nullptr;
}

Expand Down

0 comments on commit 713aafb

Please sign in to comment.