1
0
Fork 0

Really check success of getcwd(3)

`getcwd(3)' returns a NULL pointer when it fails, and a pointer to the buffer
when it succeeds. The array of characters (allocated on the stack) is not NULL,
so it cannot be used to check if `getcwd(3)' succeeded. Use the pointer
returned by `getcwd(3)' to check success.
This commit is contained in:
Augustin Fabre 2021-04-07 18:51:58 +02:00
parent 0dc47480f1
commit f2ae5e80fc
1 changed files with 2 additions and 2 deletions

View File

@ -529,8 +529,8 @@ int main(int argc, char *argv[])
/* Convert relative gopher roots to absolute roots */
if (st.server_root[0] != '/') {
char cwd[512];
getcwd(cwd, sizeof(cwd));
char cwd_buf[512];
const char *cwd = getcwd(cwd_buf, sizeof(cwd_buf));
if (cwd == NULL) {
die(&st, NULL, "unable to get current path");
}