Skip to content

Commit da00dc5

Browse files
committed
Make error handling in find_slot() more robust.
check_slot() can potentially return any value besides 0, -EIO and -EINVAL.
1 parent f826fee commit da00dc5

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

libexfat/node.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -858,21 +858,24 @@ static int find_slot(struct exfat* ef, struct exfat_node* dir,
858858
if (contiguous++ == 0)
859859
*offset = (off_t) i * sizeof(struct exfat_entry);
860860
if (contiguous == n)
861+
{
862+
int rc;
863+
861864
/* suitable slot is found, check that it's not occupied */
862-
switch (check_slot(ef, dir, *offset, n))
865+
rc = check_slot(ef, dir, *offset, n);
866+
if (rc == -EINVAL)
863867
{
864-
case 0:
865-
free(dmap);
866-
return 0;
867-
case -EIO:
868-
free(dmap);
869-
return -EIO;
870-
case -EINVAL:
871868
/* slot at (i-n) is occupied, go back and check (i-n+1) */
872869
i -= contiguous - 1;
873870
contiguous = 0;
874-
break;
875871
}
872+
else
873+
{
874+
/* slot is free or an error occurred */
875+
free(dmap);
876+
return rc;
877+
}
878+
}
876879
}
877880
else
878881
contiguous = 0;

0 commit comments

Comments
 (0)