main: check return value of getcwd()

This commit is contained in:
Daniel Eklöf 2020-02-20 18:46:45 +01:00
parent f1b1ac39f6
commit eed5052ce8
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F

6
main.c
View file

@ -314,10 +314,14 @@ main(int argc, char *const *argv)
char *cwd = NULL; char *cwd = NULL;
{ {
errno = 0;
size_t buf_len = 1024; size_t buf_len = 1024;
do { do {
cwd = realloc(cwd, buf_len); cwd = realloc(cwd, buf_len);
getcwd(cwd, buf_len); if (getcwd(cwd, buf_len) == NULL && errno != ERANGE) {
LOG_ERRNO("failed to get current working directory");
goto out;
}
buf_len *= 2; buf_len *= 2;
} while (errno == ERANGE); } while (errno == ERANGE);
} }