Skip to content

Commit 4390d87

Browse files
committed
patch 9.0.1383: xxd: combination of little endian and cols fails
Problem: xxd: combination of little endian and cols fails. (Aapo Rantalainen) Solution: Round up the space taken by the hex output. (closes #12097)
1 parent c142d65 commit 4390d87

3 files changed

Lines changed: 24 additions & 2 deletions

File tree

src/testdir/test_xxd.vim

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,4 +401,18 @@ func Test_xxd_plain_one_line()
401401
endfor
402402
endfunc
403403

404+
func Test_xxd_little_endian_with_cols()
405+
enew!
406+
call writefile(["ABCDEF"], 'Xxdin', 'D')
407+
exe 'r! ' .. s:xxd_cmd .. ' -e -c6 ' .. ' Xxdin'
408+
call assert_equal('00000000: 44434241 4645 ABCDEF', getline(2))
409+
410+
enew!
411+
call writefile(["ABCDEFGHI"], 'Xxdin', 'D')
412+
exe 'r! ' .. s:xxd_cmd .. ' -e -c9 ' .. ' Xxdin'
413+
call assert_equal('00000000: 44434241 48474645 49 ABCDEFGHI', getline(2))
414+
415+
bwipe!
416+
endfunc
417+
404418
" vim: shiftwidth=2 sts=2 expandtab

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,8 @@ static char *(features[]) =
695695

696696
static int included_patches[] =
697697
{ /* Add new patch number below this line */
698+
/**/
699+
1383,
698700
/**/
699701
1382,
700702
/**/

src/xxd/xxd.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,8 @@ main(int argc, char *argv[])
837837
{
838838
addrlen = sprintf(l, decimal_offset ? "%08ld:" : "%08lx:",
839839
((unsigned long)(n + seekoff + displayoff)));
840-
for (c = addrlen; c < LLEN; l[c++] = ' ');
840+
for (c = addrlen; c < LLEN; l[c++] = ' ')
841+
;
841842
}
842843
x = hextype == HEX_LITTLEENDIAN ? p ^ (octspergrp-1) : p;
843844
c = addrlen + 1 + (grplen * x) / octspergrp;
@@ -857,7 +858,12 @@ main(int argc, char *argv[])
857858
if (ebcdic)
858859
e = (e < 64) ? '.' : etoa64[e-64];
859860
/* When changing this update definition of LLEN above. */
860-
c = addrlen + 3 + (grplen * cols - 1)/octspergrp + p;
861+
if (hextype == HEX_LITTLEENDIAN)
862+
/* last group will be fully used, round up */
863+
c = grplen * ((cols + octspergrp - 1) / octspergrp);
864+
else
865+
c = (grplen * cols - 1) / octspergrp;
866+
c += addrlen + 3 + p;
861867
l[c++] =
862868
#ifdef __MVS__
863869
(e >= 64)

0 commit comments

Comments
 (0)