aboutsummaryrefslogtreecommitdiff
path: root/internal/intconv/uptr_int.go
blob: 1ca4c6742fde00a828bcb299d22aa379e488338f (about) (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
package intconv

import (
	"math"
)

// UintptrToInt converts v to int, returning an error if it overflows.
func UintptrToInt(v uintptr) (int, error) {
	if v > uintptr(math.MaxInt) {
		return 0, ErrOverflow
	}

	return int(v), nil
}