fix infinite loop on command not found

This commit is contained in:
IoIxD 2026-01-26 18:15:05 -07:00
commit 203aeb5540
4 changed files with 6 additions and 4 deletions

View file

@ -13,7 +13,7 @@ msh_lexer msh_lexer_new() {
l.item_list_cur = l.item_list_head; l.item_list_cur = l.item_list_head;
l.path = msh_env_get_path(); l.path = msh_env_get_path(&l.path_count);
return l; return l;
}; };
@ -148,7 +148,7 @@ static int do_exec(msh_lexer *lexer, char *cmd, char **args, int *n,
/* loop through all the path entries and check if the file exists in them. /* loop through all the path entries and check if the file exists in them.
*/ */
i = 0, *n = 0, j = 0; i = 0, *n = 0, j = 0;
while (1) { while (j >= lexer->path_count) {
full_path[*n] = lexer->path[j]; full_path[*n] = lexer->path[j];
*n += 1; *n += 1;
if (lexer->path[j] == '\0') { if (lexer->path[j] == '\0') {

View file

@ -29,6 +29,7 @@ typedef struct msh_lexer_t {
msh_lexer_item_list *item_list_head; msh_lexer_item_list *item_list_head;
msh_lexer_item_list *item_list_cur; msh_lexer_item_list *item_list_cur;
char *path; char *path;
SIZE_TYPE path_count;
} msh_lexer; } msh_lexer;
msh_lexer msh_lexer_new(); msh_lexer msh_lexer_new();

View file

@ -85,7 +85,7 @@ const char *msh_env_get(const char *key) {
return 0; return 0;
}; };
char *msh_env_get_path() { char *msh_env_get_path(SIZE_TYPE *num) {
msh_linux_env_item *env_item_tail = &env_items; msh_linux_env_item *env_item_tail = &env_items;
while (env_item_tail->next != 0) { while (env_item_tail->next != 0) {
@ -98,6 +98,7 @@ char *msh_env_get_path() {
*newenv_ptr = '\0'; *newenv_ptr = '\0';
} }
newenv_ptr++; newenv_ptr++;
*num += 1;
} }
return newenv; return newenv;
} }

View file

@ -133,7 +133,7 @@ void msh_env_set(const char *key, char *value);
* path, ending in two NULLs. * path, ending in two NULLs.
* The resulting string is owned by the caller and must be freed appropriately. * The resulting string is owned by the caller and must be freed appropriately.
*/ */
char *msh_env_get_path(); char *msh_env_get_path(SIZE_TYPE *num);
/* /*
* System path seperator * System path seperator