Details
-
Bug
-
Resolution: Out of scope
-
P3: Somewhat important
-
4.5.0, 4.5.1, 4.5.2, 4.5.3, 4.6.0, 4.6.1, 4.6.2
-
None
-
Windows 7, Qt 4.6
Description
QTemporaryFile contains a subtle bug regarding filename generation on Windows, which can cause it to fail randomly under certain circumstances.
The bug has occured on our workstation twice.
Background:
On Windows getpid() is implemented in CRT as follows:
int _getpid (void)
{
return (int)GetCurrentProcessId();
}
Please note the signature of GetCurrentProcessId() :
DWORD WINAPI GetCurrentProcessId(void);
Therefore due to the aforementioned cast of DWORD to int, getpid() can return values that are negative on Windows
Please note how the _gettemp() function threats the output of getpid() in this formula:
while (trv >= path && *trv == 'X' && pid != 0)
{ *trv-- = (pid % 10) + '0'; pid /= 10; }In case of negative pid, trv array will be filled with non-digit ascii characters.
The fix is simple - before the loop check if pid is negative and make it non-negative.