bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] Don't do unneccesary memory copies in dd.


From: Paul Eggert
Subject: Re: [PATCH] Don't do unneccesary memory copies in dd.
Date: Fri, 21 Nov 2008 11:01:44 -0800
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.3 (gnu/linux)

Pádraig Brady <address@hidden> writes:

> * src/dd.c: If output buffer size would be
> the same size as the input buffer, just use
> a single buffer to avoid redundant memory copy.

Unfortunately this patch introduced a bug into 'dd', so that it no
longer conforms to POSIX.

The C_TWOBUFS option has two effects, one having to do with whether a
single buffer is used, and the other having to do with whether output
blocks are dynamically resized to be the same size as input blocks.
This patch inadvertently caused the latter behavior to change.

Here's an example of the problem:

$ (echo 'x'; sleep 10; echo y) | dd ibs=3 obs=3

POSIX says that in this case the output data must be reblocked into
blocks of 3 bytes.  With the working 'dd', you'll see a pause of 10
seconds (because the first 'echo' outputs only 2 bytes), then the x and
y right away (because we now have all 4 input bytes, and can issue a
write of 3 bytes and a write of 1 byte).  With a buggy 'dd', you'll see
the 'x' right away (because we output a 2-byte block), then a pause of
10 seconds, then a 'y' (the other 2-byte block).

The simplest fix I see is to revert the patch.  Of course one could up
with something fancier....




reply via email to

[Prev in Thread] Current Thread [Next in Thread]