diff src/xxd/xxd.c @ 26036:c8165ec9dcad v8.2.3552

patch 8.2.3552: xxd revert does not handle end of line correctly Commit: https://github.com/vim/vim/commit/47810464aa4f9edbf222c02a860a3ec560b0b7a1 Author: DungSaga <dungsaga@users.noreply.github.com> Date: Fri Oct 22 12:55:42 2021 +0100 patch 8.2.3552: xxd revert does not handle end of line correctly Problem: Xxd revert does not handle end of line correctly. Solution: Check for newline first. (closes https://github.com/vim/vim/issues/9034)
author Bram Moolenaar <Bram@vim.org>
date Fri, 22 Oct 2021 14:00:07 +0200
parents 16aaed83522a
children 3c36cc7bd7a8
line wrap: on
line diff
--- a/src/xxd/xxd.c
+++ b/src/xxd/xxd.c
@@ -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 */
+	  while (c != '\n' && c != EOF)
+	    c = getc(fpi);
+	  if (c == EOF && ferror(fpi))
+	    die(2);
+	}
+      if (c == '\n')
+	{
 	  if (!hextype)
 	    want_off = 0;
-	  while ((c = getc(fpi)) != '\n' && c != EOF)
-	    ;
-	  if (c == EOF && ferror(fpi))
-	    die(2);
+	  p = cols;
 	  ign_garb = 1;
 	}
     }