Skip to content

Commit

Permalink
check ret value of getcwd()
Browse files Browse the repository at this point in the history
This fixes prompt on invalid drive.
See dosemu2/dosemu2#2225
  • Loading branch information
stsp committed Jul 7, 2024
1 parent c6276ff commit 4c0e0d0
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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);
Expand Down

0 comments on commit 4c0e0d0

Please sign in to comment.