[llvm-commits] [llvm] r85922 - /llvm/trunk/lib/Support/MemoryBuffer.cpp
Dan Gohman
gohman at apple.com
Wed Nov 4 11:28:19 PST 2009
On Nov 3, 2009, at 12:08 PM, Duncan Sands wrote:
> Hi Dan,
>
>>> --- llvm/trunk/lib/Support/MemoryBuffer.cpp (original)
>>> +++ llvm/trunk/lib/Support/MemoryBuffer.cpp Tue Nov 3 13:10:22 2009
>>> @@ -226,7 +226,7 @@
>>> size_t BytesLeft = FileSize;
>>> while (BytesLeft) {
>>> ssize_t NumRead = ::read(FD, BufPtr, BytesLeft);
>>> - if (NumRead != -1) {
>>> + if (NumRead > 0) {
>>> BytesLeft -= NumRead;
>>> BufPtr += NumRead;
>>> } else if (errno == EINTR) {
>> Given this, the code should explicitly set errno to 0 so that it doesn't
>> infinite loop if it reaches the end of the file and errno happens to
>> have the value EINTR.
>
> if errno is EINTR, isn't it correct to go around again, even if zero bytes
> were read?
read could return 0 and leave errno unmodified. errno could be set to
EINTR by unrelated code before the first read call. If read keeps
returning 0 for some reason, the code wouldn't recover.
Dan
More information about the llvm-commits
mailing list