Code review request "6402006: FileInputStream.available() returns negative values when reading a large file"
Alan.Bateman at oracle.com
Fri Nov 19 02:11:18 PST 2010
Mike Duigou wrote:
> Would it be possible to call GetFileSizeEx() (or add a call to GetLastError())
>> Note that if the return value is INVALID_FILE_SIZE (0xffffffff), an application must call GetLastError to determine whether the function has succeeded or failed. The reason the function may appear to fail when it has not is that lpFileSizeHigh could be non-NULL or the file size could be 0xffffffff. In this case, GetLastError will return NO_ERROR (0) upon success. Because of this behavior, it is recommended that you use GetFileSizeEx instead.
> There is a similar problem for for SetFilePosition():
>> Note Because INVALID_SET_FILE_POINTER is a valid value for the low-order DWORD of the new file pointer, you must check both the return value of the function and the error code returned by GetLastError to determine whether or not an error has occurred. If an error has occurred, the return value of SetFilePointer is INVALID_SET_FILE_POINTER and GetLastError returns a value other than NO_ERROR. For a code example that demonstrates how to check for failure, see the Remarks section in this topic.
I agree with Mike's suggestion to use GetFileSizeEx. Also, well spotted
that the SetFilePointer usage is missing a check to GetLastError. I
quickly checked the other usages of this clunky API and they seem to
check the error.
Do you plan to include a regression test for this? I know it's not nice
for tests to be create multi-GB files but this is one that we should
have caught a long time ago. If we create it as a sparse file then the
test should be relatively quick.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the core-libs-dev