On Sun, Jan 04, 2015 at 18:44, Martin Wolters wrote:

> I would have expected dd to report 5 odd length blocks here. When view-
> ing the result in hexdump, I found the byte at offset 0xA to be the
> same as in the original file, but at 0x15, 0x20, 0x2B and 0x36, they
> are replaced by the value 0.
> 
> Checking other implementations, I found FreeBSD's dd to give the exact
> result I expected (5 odd length swab blocks and the original bytes at
> the aforementioned offsets) and GNU not even trying to adhere to any
> sensible interpretation of the specification (swapping between border-
> ing blocks and all over the place).

Indeed. Without further commenting on how silly I think the swab
feature is (let alone the name), the argument to the swapbytes
function is incorrect. We should be using the recently read count, not
the total read count.

Index: dd.c
===================================================================
RCS file: /cvs/src/bin/dd/dd.c,v
retrieving revision 1.19
diff -u -p -r1.19 dd.c
--- dd.c        11 Dec 2014 20:39:06 -0000      1.19
+++ dd.c        4 Jan 2015 18:37:21 -0000
@@ -304,7 +304,7 @@ dd_in(void)
                }
 
                if (ddflags & C_SWAB) {
-                       if ((n = in.dbcnt) & 1) {
+                       if ((n = in.dbrcnt) & 1) {
                                ++st.swab;
                                --n;
                        }

Reply via email to