From f4852f7b900387f363e44ead37e86686f9c6e304 Mon Sep 17 00:00:00 2001 From: kevin Date: Sat, 14 May 2022 10:12:47 -0400 Subject: [PATCH] filesys.cpp: Add nullptr guards to isDir(), isFile(), isLink(). --- cwFileSys.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/cwFileSys.cpp b/cwFileSys.cpp index 5d5b8e8..7946109 100644 --- a/cwFileSys.cpp +++ b/cwFileSys.cpp @@ -63,6 +63,9 @@ bool cw::filesys::isDir( const char* dirStr ) errno = 0; + if( dirStr == nullptr ) + return false; + if( stat(dirStr,&s) != 0 ) { // if the dir does not exist @@ -81,6 +84,9 @@ bool cw::filesys::isFile( const char* fnStr ) struct stat s; errno = 0; + if( fnStr == nullptr ) + return false; + if( stat(fnStr,&s) != 0 ) { @@ -101,6 +107,9 @@ bool cw::filesys::isLink( const char* fnStr ) struct stat s; errno = 0; + if( fnStr == nullptr ) + return false; + if( lstat(fnStr,&s) != 0 ) { // if the file does not exist @@ -314,6 +323,9 @@ char* cw::filesys::expandPath( const char* dir ) memset(&res,0,sizeof(res)); + if( dir == nullptr ) + return nullptr; + if((sysRC = wordexp(dir,&res,flags)) != 0) { switch(sysRC)