Fix crash when username contains Unicode characters on Windows (#17)

*   Fixed bug on Windows with username containing wide characters causing the
    library to crash.
    _Le Liu_
This commit is contained in:
Le Liu 2016-11-27 19:09:42 +08:00 committed by Itay Grudev
parent e75f16a39a
commit 5aa7430f56

View File

@ -82,9 +82,7 @@ void SingleApplicationPrivate::genBlockServerName( int timeout )
// Specifies size of the buffer on input
DWORD usernameLength = UNLEN + 1;
if( GetUserName( username, &usernameLength ) ) {
char buffer[512];
size_t length = wcstombs( buffer, username, 512 );
appData.addData( buffer, length );
appData.addData( QString::fromWCharArray(username).toUtf8() );
} else {
appData.addData( QStandardPaths::standardLocations( QStandardPaths::HomeLocation ).join("").toUtf8() );
}