aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan200101 <sentrycraft123@gmail.com>2020-12-07 11:03:54 +0100
committerJan200101 <sentrycraft123@gmail.com>2020-12-07 11:03:54 +0100
commitbd2b8b26aa6052b156b256d55b24d7f7c3d57796 (patch)
treee4399e75b7f181abdc854533f91b11b526cf1d1e
parentc8ed2a0b68c69da998fde24fc2dabbfc7ceded5f (diff)
downloadpolecat-bd2b8b26aa6052b156b256d55b24d7f7c3d57796.tar.gz
polecat-bd2b8b26aa6052b156b256d55b24d7f7c3d57796.zip
add some safety around stat failures
-rw-r--r--src/common.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/common.c b/src/common.c
index 352a706..c5d9435 100644
--- a/src/common.c
+++ b/src/common.c
@@ -25,8 +25,11 @@ void print_help(const struct Command* commands, const size_t size)
struct stat getStat(const char* path)
{
- struct stat sb;
+ // fill with 0s by default in the case stat fails
+ struct stat sb = {0};
+ // the return value signifies if stat failes (e.g. file not found)
+ // unimportant for us if it fails it won't touch sb
stat(path, &sb);
return sb;
@@ -48,9 +51,10 @@ bool isDir(const char* path)
void makeDir(const char* path)
{
- struct stat st = {0};
+ // we do not care about the contents but what stat returns
+ struct stat sb;
- if (stat(path, &st) == -1)
+ if (stat(path, &sb) < 0)
{
mkdir(path, 0755);
}