fs/cromfs/fs_cromfs.c: Fixes hardfault

This commit is contained in:
David Sidrane 2018-12-06 16:42:20 -06:00 committed by Gregory Nutt
parent 931a0dc8f4
commit b30db5dcb0

View file

@ -207,7 +207,7 @@ static FAR void *cromfs_offset2addr(FAR const struct cromfs_volume_s *fs,
{
/* Zero offset is a specials case: It corresponds to a NULL address */
if (offset == 0)
if (offset == 0 || offset >= fs->cv_fsize)
{
return NULL;
}
@ -222,7 +222,7 @@ static FAR void *cromfs_offset2addr(FAR const struct cromfs_volume_s *fs,
}
/****************************************************************************
* Name: cromfs_offset2addr
* Name: cromfs_addr2offset
****************************************************************************/
static uint32_t cromfs_addr2offset(FAR const struct cromfs_volume_s *fs,
@ -1030,6 +1030,15 @@ static int cromfs_readdir(struct inode *mountpt, struct fs_dirent_s *dir)
*/
node = (FAR const struct cromfs_node_s *)cromfs_offset2addr(fs, offset);
if (node == NULL)
{
/* We signal the end of the directory by returning the
* special error -ENOENT
*/
finfo("Entry %d: End of directory\n", offset);
return -ENOENT;
}
/* Save the filename and file type */