On 10/24/2010 05:26 PM, Pádraig Brady wrote: > On a related note I was wondering if we should fall back > to increasing the buffer by +=BUFSIZ rather than *=2 > when we get ENOMEM?
I wouldn't bother, as it would lead to O(N**2) behavior, which could well be worse than the problem that it'd cure. (Currently it's not *=2, by the way, it's more like *=1.5.) I found a couple of minor problems in the patch. This comment needs to be updated, to match the new behavior: /* For a regular file, allocate a buffer that has exactly the right size.... since the buffer is now 1 byte "too large". Also, this line: if (SIZE_MAX <= alloc_off) should be changed to: if (SIZE_MAX - 2 < alloc_off) in order to detect the overflow that now occurs when st.st_size - ftello (stream) == SIZE_MAX - 1. Using it "SIZE_MAX - 2 <" rather than "SIZE_MAX - 1 <=" will make the relationship between this "2" and the "2" in "alloc_off + 2" more obvious to the reader.