diff options
author | Jan200101 <sentrycraft123@gmail.com> | 2020-12-07 11:03:54 +0100 |
---|---|---|
committer | Jan200101 <sentrycraft123@gmail.com> | 2020-12-07 11:03:54 +0100 |
commit | bd2b8b26aa6052b156b256d55b24d7f7c3d57796 (patch) | |
tree | e4399e75b7f181abdc854533f91b11b526cf1d1e | |
parent | c8ed2a0b68c69da998fde24fc2dabbfc7ceded5f (diff) | |
download | polecat-bd2b8b26aa6052b156b256d55b24d7f7c3d57796.tar.gz polecat-bd2b8b26aa6052b156b256d55b24d7f7c3d57796.zip |
add some safety around stat failures
-rw-r--r-- | src/common.c | 10 |
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); } |