From c135f989ec779f1f2d6438c2220156baaf616065 Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Fri, 4 Oct 2019 23:29:10 +0200 Subject: [PATCH] Check errors in is_dir() is_regular_file() In case of error print the error. And return right value. Improvement based on @pasis advice in https://github.com/profanity-im/profanity/pull/1036 Applying in preparation to merge that PR. --- src/common.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/common.c b/src/common.c index 2a4da006..d8ee9915 100644 --- a/src/common.c +++ b/src/common.c @@ -443,7 +443,11 @@ int is_regular_file(const char *path) { struct stat st; - stat(path, &st); + int ret = stat(path, &st); + if (ret != 0) { + perror(NULL); + return 0; + } return S_ISREG(st.st_mode); } @@ -451,7 +455,11 @@ int is_dir(const char *path) { struct stat st; - stat(path, &st); + int ret = stat(path, &st); + if (ret != 0) { + perror(NULL); + return 0; + } return S_ISDIR(st.st_mode); }