]> granicus.if.org Git - vim/commitdiff
patch 8.2.3552: xxd revert does not handle end of line correctly v8.2.3552
authorDungSaga <dungsaga@users.noreply.github.com>
Fri, 22 Oct 2021 11:55:42 +0000 (12:55 +0100)
committerBram Moolenaar <Bram@vim.org>
Fri, 22 Oct 2021 11:55:42 +0000 (12:55 +0100)
Problem:    Xxd revert does not handle end of line correctly.
Solution:   Check for newline first. (closes #9034)

src/testdir/test_xxd.vim
src/version.c
src/xxd/xxd.c

index 922c5ab3a69a8fa908876dc5a9614e7d95b6e49d..fec012212756016d2fa04b8799018aeb73012c64 100644 (file)
@@ -213,6 +213,39 @@ func Test_xxd()
   call delete('XXDfile')
 endfunc
 
+func Test_xxd_patch()
+  let cmd = 'silent !' .. s:xxd_cmd .. ' -r Xxxdin Xxxdfile; ' .. s:xxd_cmd .. ' -g1 Xxxdfile > Xxxdout'
+  call writefile(["2: 41 41", "8: 42 42"], 'Xxxdin')
+  call writefile(['::::::::'], 'Xxxdfile')
+  exe cmd
+  call assert_equal(['00000000: 3a 3a 41 41 3a 3a 3a 3a 42 42                    ::AA::::BB'], readfile('Xxxdout'))
+
+  call writefile(["2: 43 43 ", "8: 44 44"], 'Xxxdin')
+  exe cmd
+  call assert_equal(['00000000: 3a 3a 43 43 3a 3a 3a 3a 44 44                    ::CC::::DD'], readfile('Xxxdout'))
+
+  call writefile(["2: 45 45  ", "8: 46 46"], 'Xxxdin')
+  exe cmd
+  call assert_equal(['00000000: 3a 3a 45 45 3a 3a 3a 3a 46 46                    ::EE::::FF'], readfile('Xxxdout'))
+  
+  call writefile(["2: 41 41", "08: 42 42"], 'Xxxdin')
+  call writefile(['::::::::'], 'Xxxdfile')
+  exe cmd
+  call assert_equal(['00000000: 3a 3a 41 41 3a 3a 3a 3a 42 42                    ::AA::::BB'], readfile('Xxxdout'))
+
+  call writefile(["2: 43 43 ", "09: 44 44"], 'Xxxdin')
+  exe cmd
+  call assert_equal(['00000000: 3a 3a 43 43 3a 3a 3a 3a 42 44 44                 ::CC::::BDD'], readfile('Xxxdout'))
+
+  call writefile(["2: 45 45  ", "0a: 46 46"], 'Xxxdin')
+  exe cmd
+  call assert_equal(['00000000: 3a 3a 45 45 3a 3a 3a 3a 42 44 46 46              ::EE::::BDFF'], readfile('Xxxdout'))
+  
+  call delete('Xxxdin')
+  call delete('Xxxdfile')
+  call delete('Xxxdout')
+endfunc
+
 " Various ways with wrong arguments that trigger the usage output.
 func Test_xxd_usage()
   for arg in ['-c', '-g', '-o', '-s', '-l', '-X', 'one two three']
index 75c35196b8b1f23c124de48b5b8ce1d91c66ed2e..01437619b82004ccded350ed891cbf71fc543898 100644 (file)
@@ -757,6 +757,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    3552,
 /**/
     3551,
 /**/
index 749df435d2f6a323d5e94f2875d4abf9f6a7a0e5..e9dab81fbc2128f986ee284f0b26fcf969b16120 100644 (file)
@@ -131,7 +131,7 @@ extern void perror __P((char *));
 extern long int strtol();
 extern long int ftell();
 
-char version[] = "xxd 2020-02-04 by Juergen Weigert et al.";
+char version[] = "xxd 2021-10-22 by Juergen Weigert et al.";
 #ifdef WIN32
 char osver[] = " (Win32)";
 #else
@@ -318,8 +318,7 @@ huntype(
          if (fflush(fpo) != 0)
            die(3);
 #ifdef TRY_SEEK
-         c = fseek(fpo, base_off + want_off - have_off, 1);
-         if (c >= 0)
+         if (fseek(fpo, base_off + want_off - have_off, 1) >= 0)
            have_off = base_off + want_off;
 #endif
          if (base_off + want_off < have_off)
@@ -349,12 +348,16 @@ huntype(
       if (n1 < 0 && n2 < 0 && n3 < 0)
        {
          /* already stumbled into garbage, skip line, wait and see */
-         if (!hextype)
-           want_off = 0;
-         while ((c = getc(fpi)) != '\n' && c != EOF)
-           ;
+         while (c != '\n' && c != EOF)
+           c = getc(fpi);
          if (c == EOF && ferror(fpi))
            die(2);
+       }
+      if (c == '\n')
+       {
+         if (!hextype)
+           want_off = 0;
+         p = cols;
          ign_garb = 1;
        }
     }