Make sure _open_osfhandle actually returns a valid handle before assigning buffer.
This commit is contained in:
@@ -351,26 +351,48 @@ void create_console()
|
||||
// redirect unbuffered STDOUT to the console
|
||||
l_std_handle = (long)GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
h_con_handle = _open_osfhandle(l_std_handle, _O_TEXT);
|
||||
fp = _fdopen( h_con_handle, "w" );
|
||||
*stdout = *fp;
|
||||
setvbuf( stdout, NULL, _IONBF, 0 );
|
||||
if (h_con_handle == -1)
|
||||
{
|
||||
llwarns << "create_console() failed to open stdout handle" << llendl;
|
||||
}
|
||||
else
|
||||
{
|
||||
fp = _fdopen( h_con_handle, "w" );
|
||||
*stdout = *fp;
|
||||
setvbuf( stdout, NULL, _IONBF, 0 );
|
||||
}
|
||||
|
||||
// redirect unbuffered STDIN to the console
|
||||
l_std_handle = (long)GetStdHandle(STD_INPUT_HANDLE);
|
||||
h_con_handle = _open_osfhandle(l_std_handle, _O_TEXT);
|
||||
fp = _fdopen( h_con_handle, "r" );
|
||||
*stdin = *fp;
|
||||
setvbuf( stdin, NULL, _IONBF, 0 );
|
||||
if (h_con_handle == -1)
|
||||
{
|
||||
llwarns << "create_console() failed to open stdin handle" << llendl;
|
||||
}
|
||||
else
|
||||
{
|
||||
fp = _fdopen( h_con_handle, "r" );
|
||||
*stdin = *fp;
|
||||
setvbuf( stdin, NULL, _IONBF, 0 );
|
||||
}
|
||||
|
||||
// redirect unbuffered STDERR to the console
|
||||
l_std_handle = (long)GetStdHandle(STD_ERROR_HANDLE);
|
||||
h_con_handle = _open_osfhandle(l_std_handle, _O_TEXT);
|
||||
fp = _fdopen( h_con_handle, "w" );
|
||||
*stderr = *fp;
|
||||
setvbuf( stderr, NULL, _IOFBF, 1024 ); //Assigning a buffer improves speed a LOT, esp on vista/win7
|
||||
//_IOLBF is borked.
|
||||
if (h_con_handle == -1)
|
||||
{
|
||||
llwarns << "create_console() failed to open stderr handle" << llendl;
|
||||
}
|
||||
else
|
||||
{
|
||||
fp = _fdopen( h_con_handle, "w" );
|
||||
*stderr = *fp;
|
||||
setvbuf( stderr, NULL, _IOFBF, 1024 ); //Assigning a buffer improves speed a LOT, esp on vista/win7
|
||||
//_IOLBF is borked.
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
LLAppViewerWin32::LLAppViewerWin32(const char* cmd_line) :
|
||||
mCmdLine(cmd_line)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user