Skip to content

Commit

Permalink
Add null pointer checks
Browse files Browse the repository at this point in the history
  • Loading branch information
greiman committed May 15, 2020
1 parent 74d464a commit d8fe044
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=SdFat
version=1.1.2
version=1.1.3
license=MIT
author=Bill Greiman <[email protected]>
maintainer=Bill Greiman <[email protected]>
Expand Down
19 changes: 10 additions & 9 deletions src/FatLib/FatFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ bool FatFile::mkdir(FatFile* parent, const char* path, bool pFlag) {
fname_t fname;
FatFile tmpDir;

if (isOpen() || !parent->isDir()) {
if (isOpen() || !parent || !parent->isDir()) {
DBG_FAIL_MACRO;
goto fail;
}
Expand Down Expand Up @@ -306,7 +306,7 @@ bool FatFile::mkdir(FatFile* parent, fname_t* fname) {
dir_t* dir;
cache_t* pc;

if (!parent->isDir()) {
if (!parent || !parent->isDir()) {
DBG_FAIL_MACRO;
goto fail;
}
Expand Down Expand Up @@ -379,7 +379,7 @@ bool FatFile::open(FatFile* dirFile, const char* path, oflag_t oflag) {
fname_t fname;

// error if already open
if (isOpen() || !dirFile->isDir()) {
if (isOpen() || !dirFile || !dirFile->isDir()) {
DBG_FAIL_MACRO;
goto fail;
}
Expand Down Expand Up @@ -425,7 +425,7 @@ bool FatFile::open(FatFile* dirFile, uint16_t index, oflag_t oflag) {
ldir_t*ldir;

// Error if already open.
if (isOpen() || !dirFile->isDir()) {
if (isOpen() || !dirFile || !dirFile->isDir()) {
DBG_FAIL_MACRO;
goto fail;
}
Expand Down Expand Up @@ -581,8 +581,9 @@ bool FatFile::openNext(FatFile* dirFile, oflag_t oflag) {
uint8_t lfnOrd = 0;
uint16_t index;

// Check for not open and valid directory..
if (isOpen() || !dirFile->isDir() || (dirFile->curPosition() & 0X1F)) {
// Check for not open and valid directory.
if (isOpen() || !dirFile || !dirFile->isDir()
|| (dirFile->curPosition() & 0X1F)) {
DBG_FAIL_MACRO;
goto fail;
}
Expand Down Expand Up @@ -643,7 +644,7 @@ bool FatFile::openParent(FatFile* dirFile) {
uint32_t ddc;
cache_t* cb;

if (isOpen() || !dirFile->isOpen()) {
if (isOpen() || !dirFile || !dirFile->isOpen()) {
goto fail;
}
if (dirFile->m_dirCluster == 0) {
Expand Down Expand Up @@ -1235,8 +1236,8 @@ bool FatFile::timestamp(FatFile* file) {
dir_t* dir;
dir_t srcDir;

// most be files get timestamps
if (!isFile() || !file->isFile() || !file->dirEntry(&srcDir)) {
// must be files to get timestamps
if (!isFile() || !file || !file->isFile() || !file->dirEntry(&srcDir)) {
DBG_FAIL_MACRO;
goto fail;
}
Expand Down
2 changes: 1 addition & 1 deletion src/FatLib/FatFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@ class FatFile {
* \return true for success else false.
*/
static bool setCwd(FatFile* dir) {
if (!dir->isDir()) {
if (!dir || !dir->isDir()) {
return false;
}
m_cwd = dir;
Expand Down
2 changes: 1 addition & 1 deletion src/FatLib/FatFileLFN.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ bool FatFile::open(FatFile* dirFile, fname_t* fname, oflag_t oflag) {
ldir_t* ldir;
size_t len = fname->len;

if (!dirFile->isDir() || isOpen()) {
if (!dirFile || dirFile->isDir() || isOpen()) {
DBG_FAIL_MACRO;
goto fail;
}
Expand Down

0 comments on commit d8fe044

Please sign in to comment.