From 79fee676a499ccd7f55986a3e92bd4608d237aed Mon Sep 17 00:00:00 2001 From: biglyderv Date: Mon, 24 Mar 2025 23:55:55 -0400 Subject: [PATCH] fix segfault --- src/command.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/command.c b/src/command.c index 4f2999a..c983385 100644 --- a/src/command.c +++ b/src/command.c @@ -63,10 +63,15 @@ int get_command(char *command, char *command_re, char **sort_tmp) { } int cl = strlen(command); + if (cl == 0) return 0; + command[cl - 1] = '\0'; for (int i = 0; i < cl - 1; i++) { command[i] = tolower(command[i]); + if ((i == 0 || i == cl - 1) && command[i] == ';') { + command[i] = ' '; + } } sort_tmp[0] = command; @@ -76,6 +81,10 @@ int get_command(char *command, char *command_re, char **sort_tmp) { sort_tmp[i] = strstr(sort_tmp[i - 1], ";"); if (sort_tmp[i] == 0) break; + if (strlen(sort_tmp[i]) < 2) { + sort_tmp[i][0] = '\0'; + break; + } sort_tmp[i][0] = '\0'; sort_tmp[i]++; }