On 01/23/2013 10:48 AM, Ondrej Oprala wrote:
+ /* Delay buffer allocation if possible. */
+ if ((skip_records > OFF_T_MAX / input_blocksize)
+ || 0 > skip_via_lseek (input_file, STDIN_FILENO, 0, SEEK_CUR))
+ alloc_ibuf ();
- /* Write a sentinel to the slop after the buffer,
- to allow efficient checking for NUL blocks. */
- assert (sizeof (uintptr_t) <= OUTPUT_BLOCK_SLOP);
- memset (obuf + output_blocksize, 1, sizeof (uintptr_t));
+ if ((seek_records > OFF_T_MAX / output_blocksize)
+ || 0 > skip_via_lseek (output_file, STDOUT_FILENO, 0, SEEK_CUR))
+ alloc_obuf ();
This doesn't look right.
skip_via_lseek() doesn't support lseek(..., 0, SEEK_CUR)
and may always warn for tape devices?
Also does skip bytes need to be considered?
Also you don't always need to allocate both buffers.
How about avoiding new conditions altogether and just
alloc_[io]buf() before they're needed
(i.e. closer to the read() as I suggested originally).
Also I adjusted the memory limits in the test,
to reduce the chances of false positives,
and bolstered the test cases to cater for the
new allocation calls within skip().
I'll push the attached soon.
thanks,
Pádraig.