Skip to content

Commit

Permalink
Merge pull request #41 from cpuguy83/fix_int_overflow
Browse files Browse the repository at this point in the history
Do not overflow int for 32bit builds
  • Loading branch information
estesp committed Mar 24, 2021
2 parents 0e92c22 + 53fd78a commit d5c4544
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions zfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ const (
// active := filepath.Join(dataset.Name, id)
// committed := active + "@" + snapshotSuffix
snapshotSuffix = "snapshot"

// Using this typed MaxInt64 to prevent integer overlow on 32bit
maxSnapshotSize int64 = math.MaxInt64
)

type snapshotter struct {
Expand Down Expand Up @@ -140,8 +143,8 @@ func (z *snapshotter) usage(ctx context.Context, key string) (snapshots.Usage, e
return snapshots.Usage{}, err
}

if sDataset.Used > math.MaxInt64 {
return snapshots.Usage{}, errors.Errorf("Dataset size exceeds maximum snapshot size of %v bytes", math.MaxInt64)
if int64(sDataset.Used) > maxSnapshotSize {
return snapshots.Usage{}, errors.Errorf("Dataset size exceeds maximum snapshot size of %d bytes", maxSnapshotSize)
}

usage = snapshots.Usage{
Expand Down

0 comments on commit d5c4544

Please sign in to comment.