fix string copy overlay
authorLaurent Mazet <mazet@softndesign.org>
Fri, 29 Dec 2023 20:55:37 +0000 (21:55 +0100)
committerLaurent Mazet <mazet@softndesign.org>
Fri, 29 Dec 2023 20:55:37 +0000 (21:55 +0100)
hexdump.c

index 8a085616731ce23ec2e92cb4aa4636c43c62feb5..77a413547e7936d7803a9d536527bb07ea3d9016 100644 (file)
--- a/hexdump.c
+++ b/hexdump.c
@@ -59,7 +59,7 @@ int usage (int ret)
     fprintf (fd, "commands: [/hstr/|addr|+nb] [a hstr] [d nb|-] [i hstr] [p nb|-] [s/h1/h2/[g]]\n");
     fprintf (fd, " addr: move to address (0... octal, [1-9]... deci, 0x... hexa)\n");
     fprintf (fd, " +nb: move to offset (0... octal, [1-9]... deci, 0x... hexa)\n");
-    fprintf (fd, " //: move to hexa stringi hstr\n");
+    fprintf (fd, " //: move to hexa string hstr\n");
     fprintf (fd, " a : append hexa string hstr to current address\n");
     fprintf (fd, " d : delete nb bytes (- until end file)\n");
     fprintf (fd, " i : insert hexa string hstr to current address\n");
@@ -482,8 +482,15 @@ int main (int argc, char *argv[])
         case 'e':
             arg = (arg[2]) ? arg + 2 : (--argc > 0) ? *(++argv) : NULL;
             if (arg) {
-                commands = (commands == NULL) ? arg :
-                    strcat (strcat (commands, " "), arg);
+                //commands = (commands == NULL) ? arg :
+                //    strcat (strcat (commands, " "), arg);
+                if (commands == NULL) {
+                    commands = arg;
+                } else {
+                    char *tmp = (char *) malloc (strlen (arg) + 1);
+                    strcat (strcat (commands, " "), strcpy (tmp, arg));
+                   free (tmp);
+                }
             }
             break;
         case 'i':