[BUG_FIXED] Fix a annoying regression about "the buffer passed to GetFullPathName was too small!" message dialog.

This commit is contained in:
Don Ho 2015-05-06 20:45:56 +02:00
parent a2a75be11d
commit 9aa5d708ed

View File

@ -36,35 +36,22 @@
typedef std::vector<const TCHAR*> ParamVector; typedef std::vector<const TCHAR*> ParamVector;
bool checkSingleFile( _In_z_ PCTSTR const commandLine) { bool checkSingleFile(const TCHAR *commandLine)
const rsize_t strLen = _tcslen( commandLine ); {
if ( strLen == 0 ) { if (!commandLine || lstrlen(commandLine) == 0)
return false; return false;
}
const rsize_t fullpathBufSize = MAX_PATH;
TCHAR fullpath[ fullpathBufSize ] = { 0 };
//If [GetFullPathName] succeeds, the return value is the length, in TCHARs, of the string copied to lpBuffer, not including the terminating null character. TCHAR fullpath[MAX_PATH] = {0};
//If the lpBuffer buffer is too small to contain the path, the return value [of GetFullPathName] is the size, in TCHARs, of the buffer that is required to hold the path and the terminating null character. const DWORD fullpathResult = ::GetFullPathName(commandLine, MAX_PATH, fullpath, NULL);
//If [GetFullPathName] fails for any other reason, the return value is zero. To get extended error information, call GetLastError.
const DWORD fullpathResult = ::GetFullPathName(commandLine, fullpathBufSize, fullpath, NULL); if (fullpathResult == 0)
if ( fullpathResult == 0 )
{
MessageBoxA( NULL, "GetFullPathName failed with some unexpected error!", "checkSingleFile failed!!", MB_OK );
MessageBox( NULL, commandLine, TEXT( "path that failed:" ), MB_OK );
return false; return false;
}
if ( fullpathResult > fullpathBufSize )
{
MessageBoxA( NULL, "the buffer passed to GetFullPathName was too small!", "checkSingleFile failed!!", MB_OK );
MessageBox( NULL, commandLine, TEXT( "path that failed:" ), MB_OK );
return false;
}
if (::PathFileExists(fullpath)) { if (fullpathResult > MAX_PATH)
return false;
if (::PathFileExists(fullpath))
return true; return true;
}
return false; return false;
} }