shithub: furgit

ref: c8dd7d3b44c93a664dddc0c4619d336c6e13d2a8
dir: /internal/intconv/uptr_int.go/

View raw version
package intconv

import (
	"fmt"
	"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, fmt.Errorf("intconv: uintptr %d overflows int", v)
	}

	return int(v), nil
}