]> granicus.if.org Git - vim/commitdiff
patch 8.2.3641: xxd code has duplicate expressions v8.2.3641
authorDungSaga <dungsaga@users.noreply.github.com>
Mon, 22 Nov 2021 11:57:31 +0000 (11:57 +0000)
committerBram Moolenaar <Bram@vim.org>
Mon, 22 Nov 2021 11:57:31 +0000 (11:57 +0000)
Problem:    Xxd code has duplicate expressions.
Solution:   Refactor to avoid duplication. (closes #9185)

src/version.c
src/xxd/xxd.c

index a83ff61bca0c3e697824ab62134f1dd0ba9a51fe..99c8a26972133c8cb725b2f51ca1a1e529ba949b 100644 (file)
@@ -757,6 +757,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    3641,
 /**/
     3640,
 /**/
index e2f893b7da82dc8bb5c207c0b9527540fa047f23..cef3c61279f24d5ea420a8f23b882fd1b756b95d 100644 (file)
@@ -811,24 +811,16 @@ main(int argc, char *argv[])
     {
       if (p == 0)
        {
-         if (decimal_offset)
-               addrlen = sprintf(l, "%08ld:",
-                                 ((unsigned long)(n + seekoff + displayoff)));
-         else
-               addrlen = sprintf(l, "%08lx:",
+         addrlen = sprintf(l, decimal_offset ? "%08ld:" : "%08lx:",
                                  ((unsigned long)(n + seekoff + displayoff)));
          for (c = addrlen; c < LLEN; l[c++] = ' ');
        }
-      if (hextype == HEX_NORMAL)
-       {
-         l[c = (addrlen + 1 + (grplen * p) / octspergrp)] = hexx[(e >> 4) & 0xf];
-         l[++c]                                  = hexx[ e       & 0xf];
-       }
-      else if (hextype == HEX_LITTLEENDIAN)
+      if (hextype == HEX_NORMAL || hextype == HEX_LITTLEENDIAN)
        {
-         int x = p ^ (octspergrp-1);
-         l[c = (addrlen + 1 + (grplen * x) / octspergrp)] = hexx[(e >> 4) & 0xf];
-         l[++c]                                  = hexx[ e       & 0xf];
+         int x = hextype == HEX_NORMAL ? p : p ^ (octspergrp-1);
+         l[c = (addrlen + 1 + (grplen * x) / octspergrp)]
+                = hexx[(e >> 4) & 0xf];
+         l[++c] = hexx[e & 0xf];
        }
       else /* hextype == HEX_BITS */
        {