diff --git a/user/apps/shell/cmd.c b/user/apps/shell/cmd.c index f37ffbe8..35800091 100644 --- a/user/apps/shell/cmd.c +++ b/user/apps/shell/cmd.c @@ -181,7 +181,7 @@ int shell_cmd_cd(int argc, char **argv) goto fail; ; // 出错则直接忽略 } - else + else // ======进入相对路径===== { int dest_offset = 0; if (dest_len > 2) @@ -191,7 +191,7 @@ int shell_cmd_cd(int argc, char **argv) } int new_len = current_dir_len + dest_len - dest_offset; - // ======进入相对路径===== + if (new_len >= SHELL_CWD_MAX_SIZE - 1) { printf("ERROR: Path too long!\n"); @@ -210,7 +210,8 @@ int shell_cmd_cd(int argc, char **argv) if (chdir(new_path) == 0) // 成功切换目录 { free(shell_current_path); - new_path[new_len] = '\0'; + // printf("new_path=%s, newlen= %d\n", new_path, new_len); + new_path[new_len+1] = '\0'; shell_current_path = new_path; goto done; } diff --git a/user/apps/shell/shell.c b/user/apps/shell/shell.c index dfacafb0..4f6c99cf 100644 --- a/user/apps/shell/shell.c +++ b/user/apps/shell/shell.c @@ -73,9 +73,9 @@ int main() int kb_fd = open(kb_file_path, 0); // printf("keyboard fd = %d\n", kb_fd); print_ascii_logo(); - printf("before mkdir\n"); - mkdir("/aaac", 0); - printf("after mkdir\n"); + // printf("before mkdir\n"); + // mkdir("/aaac", 0); + // printf("after mkdir\n"); main_loop(kb_fd); while (1) ;