Skip to content

Commit

Permalink
Really check success of getcwd(3)
Browse files Browse the repository at this point in the history
`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.
  • Loading branch information
augfab committed Apr 7, 2021
1 parent 0dc4748 commit f2ae5e8
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/gophernicus.c
Expand Up @@ -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");
}
Expand Down

0 comments on commit f2ae5e8

Please sign in to comment.