From f2ae5e80fcbd842a49e6ec82fc94e07f1560a969 Mon Sep 17 00:00:00 2001 From: Augustin Fabre Date: Wed, 7 Apr 2021 18:51:58 +0200 Subject: [PATCH] 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. --- src/gophernicus.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gophernicus.c b/src/gophernicus.c index 250d917..064711c 100644 --- a/src/gophernicus.c +++ b/src/gophernicus.c @@ -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"); }