bug 280522 misplaced null after WideCharToMultiByte conversion. Thanks to
Christian Franke for the nsToolkit.cpp patch (r=dveditz,sr=dbaron). nsNativeAppSupportWin.cpp patch r/sr=bzbarsky. git-svn-id: svn://10.0.0.236/trunk@168769 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
parent
9861051f37
commit
d6fa609683
@ -192,26 +192,28 @@ int ConvertAtoW(LPCSTR aStrInA, int aBufferSize, LPWSTR aStrOutW)
|
||||
|
||||
int ConvertWtoA(LPCWSTR aStrInW, int aBufferSizeOut, LPSTR aStrOutA)
|
||||
{
|
||||
int numCharsConverted;
|
||||
char defaultStr[] = "?";
|
||||
|
||||
if ((!aStrInW) || (!aStrOutA))
|
||||
if ((!aStrInW) || (!aStrOutA) || (aBufferSizeOut <= 0))
|
||||
return 0;
|
||||
|
||||
aStrOutA[0] = '\0';
|
||||
int numCharsConverted = WideCharToMultiByte(CP_ACP, 0, aStrInW, -1,
|
||||
aStrOutA, aBufferSizeOut, "?", NULL);
|
||||
|
||||
numCharsConverted = WideCharToMultiByte(CP_ACP, 0, aStrInW, -1,
|
||||
aStrOutA, aBufferSizeOut, defaultStr, NULL);
|
||||
|
||||
if (!numCharsConverted)
|
||||
return 0 ;
|
||||
|
||||
if (numCharsConverted < aBufferSizeOut) {
|
||||
*(aStrOutA+numCharsConverted) = '\0' ; // Null terminate
|
||||
return (numCharsConverted) ;
|
||||
if (!numCharsConverted) {
|
||||
if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
|
||||
// Overflow, add missing null termination but return 0
|
||||
aStrOutA[aBufferSizeOut-1] = '\0';
|
||||
}
|
||||
else {
|
||||
// Other error, clear string and return 0
|
||||
aStrOutA[0] = '\0';
|
||||
}
|
||||
}
|
||||
else if (numCharsConverted < aBufferSizeOut) {
|
||||
// Add 2nd null (really necessary?)
|
||||
aStrOutA[numCharsConverted] = '\0';
|
||||
}
|
||||
|
||||
return 0 ;
|
||||
return numCharsConverted;
|
||||
}
|
||||
|
||||
BOOL CallOpenSaveFileNameA(LPOPENFILENAMEW aFileNameW, BOOL aOpen)
|
||||
@ -390,8 +392,8 @@ LRESULT WINAPI nsSendMessage(HWND aWnd, UINT aMsg, WPARAM awParam, LPARAM alPara
|
||||
"Warning. Make sure sending non-Unicode string to ::SendMessage().");
|
||||
if (WM_SETTEXT == aMsg) {
|
||||
char title[MAX_PATH];
|
||||
if (alParam)
|
||||
ConvertWtoA((LPCWSTR)alParam, MAX_CLASS_NAME, title);
|
||||
if (alParam) // Note: Window titles are truncated to 159 chars by Windows
|
||||
ConvertWtoA((LPCWSTR)alParam, MAX_PATH, title);
|
||||
return SendMessageA(aWnd, aMsg, awParam, (LPARAM)&title);
|
||||
}
|
||||
|
||||
|
||||
@ -120,9 +120,8 @@ static char* GetACPString(const nsString& aStr)
|
||||
char * acp = new char[ acplen ];
|
||||
if( acp ) {
|
||||
int outlen = ::WideCharToMultiByte( CP_ACP, 0, aStr.get(), aStr.Length(),
|
||||
acp, acplen, NULL, NULL );
|
||||
if ( outlen >= 0)
|
||||
acp[ outlen ] = '\0'; // null terminate
|
||||
acp, acplen-1, NULL, NULL );
|
||||
acp[ outlen ] = '\0'; // null terminate
|
||||
}
|
||||
return acp;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user