From 40c510711cc33b03ff8ea1d3f1abc3636f36a208 Mon Sep 17 00:00:00 2001 From: Laurent Mazet Date: Fri, 29 Dec 2023 21:55:37 +0100 Subject: [PATCH] fix string copy overlay --- hexdump.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/hexdump.c b/hexdump.c index 8a08561..77a4135 100644 --- 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': -- 2.30.2