# HG changeset patch # User Bram Moolenaar # Date 1638358204 -3600 # Node ID d227481dbe8eb01cb3b1911bbfc4782ea23baefe # Parent 9722ad38bd53fdbc5cdd4fd91b3a6ada15b074ef patch 8.2.3714: some unused assignments and ugly code in xxd Commit: https://github.com/vim/vim/commit/7e5503c17a3f142e6b28f344d899c9ab9e75a844 Author: DungSaga Date: Wed Dec 1 11:24:52 2021 +0000 patch 8.2.3714: some unused assignments and ugly code in xxd Problem: Some unused assignments and ugly code in xxd. Solution: Leave out assignments. Use marcro for fprintf(). (closes https://github.com/vim/vim/issues/9246) diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -754,6 +754,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 3714, +/**/ 3713, /**/ 3712, diff --git a/src/xxd/xxd.c b/src/xxd/xxd.c --- a/src/xxd/xxd.c +++ b/src/xxd/xxd.c @@ -275,12 +275,8 @@ fputs_or_die(char *s, FILE *fpo) perror_exit(3); } - static void -fprintf_or_die(FILE *fpo, char *format, char *s, int d) -{ - if (fprintf(fpo, format, s, d) < 0) - perror_exit(3); -} +/* Use a macro to allow for different arguments. */ +#define FPRINTF_OR_DIE(args) if (fprintf args < 0) perror_exit(3) static void fclose_or_die(FILE *fpi, FILE *fpo) @@ -377,7 +373,7 @@ huntype( have_off = base_off + want_off; #endif if (base_off + want_off < have_off) - error_exit(5, "sorry, cannot seek backwards."); + error_exit(5, "Sorry, cannot seek backwards."); for (; have_off < base_off + want_off; have_off++) putc_or_die(0, fpo); } @@ -714,7 +710,7 @@ main(int argc, char *argv[]) if (revert) { if (hextype && (hextype != HEX_POSTSCRIPT)) - error_exit(-1, "sorry, cannot revert this type of hexdump"); + error_exit(-1, "Sorry, cannot revert this type of hexdump"); return huntype(fp, fpo, cols, hextype, negseek ? -seekoff : seekoff); } @@ -728,7 +724,7 @@ main(int argc, char *argv[]) e = fseek(fp, negseek ? -seekoff : seekoff, negseek ? SEEK_END : SEEK_SET); if (e < 0 && negseek) - error_exit(4, "sorry cannot seek."); + error_exit(4, "Sorry, cannot seek."); if (e >= 0) seekoff = ftell(fp); else @@ -737,9 +733,9 @@ main(int argc, char *argv[]) long s = seekoff; while (s--) - if ((c = getc_or_die(fp)) == EOF) + if (getc_or_die(fp) == EOF) { - error_exit(4, "sorry cannot seek."); + error_exit(4, "Sorry, cannot seek."); } } } @@ -748,7 +744,7 @@ main(int argc, char *argv[]) { if (fp != stdin) { - fprintf_or_die(fpo, "unsigned char %s", isdigit((int)argv[1][0]) ? "__" : "", 0); + FPRINTF_OR_DIE((fpo, "unsigned char %s", isdigit((int)argv[1][0]) ? "__" : "")); for (e = 0; (c = argv[1][e]) != 0; e++) putc_or_die(isalnum(c) ? CONDITIONAL_CAPITALIZE(c) : '_', fpo); fputs_or_die("[] = {\n", fpo); @@ -758,8 +754,8 @@ main(int argc, char *argv[]) c = 0; while ((length < 0 || p < length) && (c = getc_or_die(fp)) != EOF) { - fprintf_or_die(fpo, (hexx == hexxa) ? "%s0x%02x" : "%s0X%02X", - (p % cols) ? ", " : (!p ? " " : ",\n "), c); + FPRINTF_OR_DIE((fpo, (hexx == hexxa) ? "%s0x%02x" : "%s0X%02X", + (p % cols) ? ", " : (!p ? " " : ",\n "), c)); p++; } @@ -769,10 +765,10 @@ main(int argc, char *argv[]) if (fp != stdin) { fputs_or_die("};\n", fpo); - fprintf_or_die(fpo, "unsigned int %s", isdigit((int)argv[1][0]) ? "__" : "", 0); + FPRINTF_OR_DIE((fpo, "unsigned int %s", isdigit((int)argv[1][0]) ? "__" : "")); for (e = 0; (c = argv[1][e]) != 0; e++) putc_or_die(isalnum(c) ? CONDITIONAL_CAPITALIZE(c) : '_', fpo); - fprintf_or_die(fpo, "_%s = %d;\n", capitalize ? "LEN" : "len", p); + FPRINTF_OR_DIE((fpo, "_%s = %d;\n", capitalize ? "LEN" : "len", p)); } fclose_or_die(fp, fpo); @@ -782,7 +778,6 @@ main(int argc, char *argv[]) if (hextype == HEX_POSTSCRIPT) { p = cols; - e = 0; while ((length < 0 || n < length) && (e = getc_or_die(fp)) != EOF) { putc_or_die(hexx[(e >> 4) & 0xf], fpo); @@ -807,7 +802,6 @@ main(int argc, char *argv[]) else /* hextype == HEX_BITS */ grplen = 8 * octspergrp + 1; - e = 0; while ((length < 0 || n < length) && (e = getc_or_die(fp)) != EOF) { int x;