Bug 1082576 - Fix the XPCOM library loading error reporting code; r=froydnj
authorEhsan Akhgari <ehsan@mozilla.com>
Tue, 14 Oct 2014 19:28:24 -0400
changeset 210470 782a7f579e7b1d5144a84fb83c12cb28af71c512
parent 210469 556ad64e03e280103424754e404cc402b775dc3a
child 210471 9b99cd13756daaa46a0e8c3b72fe49e1fc4177b7
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersfroydnj
bugs1082576
milestone36.0a1
Bug 1082576 - Fix the XPCOM library loading error reporting code; r=froydnj We build without UNICODE, so we end up calling the ANSI version of the function, and then we would attempt to interpret the resulting narrow char buffer as a wide char buffer.
xpcom/glue/standalone/nsXPCOMGlue.cpp
--- a/xpcom/glue/standalone/nsXPCOMGlue.cpp
+++ b/xpcom/glue/standalone/nsXPCOMGlue.cpp
@@ -45,35 +45,35 @@ static bool do_preload = false;
 typedef HINSTANCE LibHandleType;
 
 static LibHandleType
 GetLibHandle(pathstr_t aDependentLib)
 {
   LibHandleType libHandle =
     LoadLibraryExW(aDependentLib, nullptr, LOAD_WITH_ALTERED_SEARCH_PATH);
 
+#ifdef DEBUG
   if (!libHandle) {
     DWORD err = GetLastError();
-#ifdef DEBUG
     LPVOID lpMsgBuf;
-    FormatMessage(
+    FormatMessageW(
       FORMAT_MESSAGE_ALLOCATE_BUFFER |
       FORMAT_MESSAGE_FROM_SYSTEM |
       FORMAT_MESSAGE_IGNORE_INSERTS,
       nullptr,
       err,
       MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
-      (LPTSTR)&lpMsgBuf,
+      (LPWSTR)&lpMsgBuf,
       0,
       nullptr
     );
     wprintf(L"Error loading %ls: %s\n", aDependentLib, lpMsgBuf);
     LocalFree(lpMsgBuf);
+  }
 #endif
-  }
 
   return libHandle;
 }
 
 static NSFuncPtr
 GetSymbol(LibHandleType aLibHandle, const char* aSymbol)
 {
   return (NSFuncPtr)GetProcAddress(aLibHandle, aSymbol);