From 4c0e0d0f7efc6df99e44fa395c0ac39e2c1ad2b4 Mon Sep 17 00:00:00 2001 From: Stas Sergeev Date: Sun, 7 Jul 2024 11:43:55 +0300 Subject: [PATCH] check ret value of getcwd() This fixes prompt on invalid drive. See https://github.com/dosemu2/dosemu2/issues/2225 --- src/command.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/command.c b/src/command.c index 645ccbe..0e3897e 100644 --- a/src/command.c +++ b/src/command.c @@ -395,6 +395,7 @@ static void output_prompt(void) { char cur_drive_and_path[MAXPATH]; const char *promptvar = getenv("PROMPT"); + char *cwd; if (need_to_crlf_at_next_prompt) { @@ -405,7 +406,9 @@ static void output_prompt(void) if (promptvar == NULL) promptvar = "$p$g"; - getcwd(cur_drive_and_path, MAXPATH); + cwd = getcwd(cur_drive_and_path, MAXPATH); + if (!cwd) + strcpy(cur_drive_and_path, "invalid"); /* The disk letter is changed to upper-case */ cur_drive_and_path[0] = toupper(cur_drive_and_path[0]); conv_unix_path_to_ms_dos(cur_drive_and_path);