Patch 8.2.3594
Problem: Xxd code is a bit difficult to understand.
Solution: Move some lines to a separate function. (closes #9037)
Files: src/xxd/xxd.c
*** ../vim-8.2.3593/src/xxd/xxd.c 2021-10-22 15:55:27.778135397 +0100
--- src/xxd/xxd.c 2021-11-14 13:41:52.541468093 +0000
***************
*** 253,258 ****
--- 253,286 ----
}
/*
+ * If "c" is a hex digit, return the value.
+ * Otherwise return -1.
+ */
+ static int
+ parse_hex_digit(int c)
+ {
+ return (c >= '0' && c <= '9') ? c - '0'
+ : (c >= 'a' && c <= 'f') ? c - 'a' + 10
+ : (c >= 'A' && c <= 'F') ? c - 'A' + 10
+ : -1;
+ }
+
+ /*
+ * Ignore text on "fpi" until end-of-line or end-of-file.
+ * Return the '\n' or EOF character.
+ * When an error is encountered exit with an error message.
+ */
+ static int
+ skip_to_eol(FILE *fpi, int c)
+ {
+ while (c != '\n' && c != EOF)
+ c = getc(fpi);
+ if (c == EOF && ferror(fpi))
+ perror_exit(2);
+ return c;
+ }
+
+ /*
* Max. cols binary characters are decoded from the input stream per line.
* Two adjacent garbage characters after evaluated data delimit valid data.
* Everything up to the next newline is discarded.
***************
*** 286,303 ****
n3 = n2;
n2 = n1;
! if (c >= '0' && c <= '9')
! n1 = c - '0';
! else if (c >= 'a' && c <= 'f')
! n1 = c - 'a' + 10;
! else if (c >= 'A' && c <= 'F')
! n1 = c - 'A' + 10;
! else
! {
! n1 = -1;
! if (ign_garb)
! continue;
! }
ign_garb = 0;
--- 314,322 ----
n3 = n2;
n2 = n1;
! n1 = parse_hex_digit(c);
! if (n1 == -1 && ign_garb)
! continue;
ign_garb = 0;
***************
*** 317,323 ****
if (fflush(fpo) != 0)
perror_exit(3);
#ifdef TRY_SEEK
! 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)
--- 336,342 ----
if (fflush(fpo) != 0)
perror_exit(3);
#ifdef TRY_SEEK
! if (fseek(fpo, base_off + want_off - have_off, SEEK_CUR) >= 0)
have_off = base_off + want_off;
#endif
if (base_off + want_off < have_off)
***************
*** 335,354 ****
want_off++;
n1 = -1;
if (!hextype && (++p >= cols))
! {
! /* skip the rest of the line as garbage */
! n2 = -1;
! n3 = -1;
! }
! }
! 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))
! perror_exit(2);
}
if (c == '\n')
{
if (!hextype)
--- 354,366 ----
want_off++;
n1 = -1;
if (!hextype && (++p >= cols))
! /* skip the rest of the line as garbage */
! c = skip_to_eol(fpi, c);
}
+ else if (n1 < 0 && n2 < 0 && n3 < 0)
+ /* already stumbled into garbage, skip line, wait and see */
+ c = skip_to_eol(fpi, c);
+
if (c == '\n')
{
if (!hextype)
***************
*** 360,366 ****
if (fflush(fpo) != 0)
perror_exit(3);
#ifdef TRY_SEEK
! fseek(fpo, 0L, 2);
#endif
if (fclose(fpo) != 0)
perror_exit(3);
--- 372,378 ----
if (fflush(fpo) != 0)
perror_exit(3);
#ifdef TRY_SEEK
! fseek(fpo, 0L, SEEK_END);
#endif
if (fclose(fpo) != 0)
perror_exit(3);
***************
*** 682,690 ****
{
#ifdef TRY_SEEK
if (relseek)
! e = fseek(fp, negseek ? -seekoff : seekoff, 1);
else
! e = fseek(fp, negseek ? -seekoff : seekoff, negseek ? 2 : 0);
if (e < 0 && negseek)
error_exit(4, "sorry cannot seek.");
if (e >= 0)
--- 694,703 ----
{
#ifdef TRY_SEEK
if (relseek)
! e = fseek(fp, negseek ? -seekoff : seekoff, SEEK_CUR);
else
! e = fseek(fp, negseek ? -seekoff : seekoff,
! negseek ? SEEK_END : SEEK_SET);
if (e < 0 && negseek)
error_exit(4, "sorry cannot seek.");
if (e >= 0)
*** ../vim-8.2.3593/src/version.c 2021-11-14 11:41:27.264457621 +0000
--- src/version.c 2021-11-14 13:44:37.452953447 +0000
***************
*** 759,760 ****
--- 759,762 ----
{ /* Add new patch number below this line */
+ /**/
+ 3594,
/**/
--
ARTHUR: Will you ask your master if he wants to join my court at Camelot?!
GUARD #1: But then of course African swallows are not migratory.
GUARD #2: Oh, yeah...
GUARD #1: So they couldn't bring a coconut back anyway...
The Quest for the Holy Grail (Monty Python)
/// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/vim_dev/20211114134711.BB48F1C43EA%40moolenaar.net.