From c5e42b972f0d49a8e50c937304f2aac23dbd1252 Mon Sep 17 00:00:00 2001 From: Brian Ryner Date: Wed, 7 Dec 2022 14:27:20 +1100 Subject: [PATCH] Truncate the result of Getfsstat to the item count that is returned. This count may be less than what was returned by the first call to Getfsstat. --- disk/disk_darwin.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/disk/disk_darwin.go b/disk/disk_darwin.go index 0877b76..15c0934 100644 --- a/disk/disk_darwin.go +++ b/disk/disk_darwin.go @@ -20,9 +20,11 @@ func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, erro return ret, err } fs := make([]unix.Statfs_t, count) - if _, err = unix.Getfsstat(fs, unix.MNT_WAIT); err != nil { + count, err := unix.Getfsstat(fs, unix.MNT_WAIT) + if err != nil { return ret, err } + fs = fs[:count] // Actual count may be less than from the first call. for _, stat := range fs { opts := []string{"rw"} if stat.Flags&unix.MNT_RDONLY != 0 {