Skip to content

Commit

Permalink
Merge branch 'sveinbjornt:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
cooljeanius authored Nov 5, 2023
2 parents e9a620c + 87165b6 commit 10f8d46
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions source/Util/FSUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,18 @@ + (NSDictionary *)mountedFileSystems {
return @{};
}
if (fs_count > MAX_FILESYSTEMS) {
// We set a maximum number of filesystems to prevent
// a stack overflow.
// TODO: Manually allocate memory from heap instead of using stack
// to handle an arbitrary number of filesystems.
fprintf(stderr, "Too many filesystems, bailing");
return @{};
}

struct statfs buf[fs_count];
getfsstat(buf, fs_count * sizeof(buf[0]), MNT_NOWAIT);

NSMutableDictionary *fsdict = [NSMutableDictionary dictionary];
NSMutableDictionary *fsdict = [NSMutableDictionary new];

for (int i = 0; i < fs_count; ++i) {
dev_t fsid = buf[i].f_fsid.val[0];
Expand All @@ -68,7 +72,7 @@ + (NSDictionary *)mountedFileSystems {
};
}

return [fsdict copy];
return [fsdict copy]; // Return immutable copy
}

@end

0 comments on commit 10f8d46

Please sign in to comment.