diff --git a/.golangci.yml b/.golangci.yml index eeeb28be1..bd370b77e 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -26,11 +26,11 @@ linters: enable: - asciicheck - bodyclose + - copyloopvar # - dogsled # - dupl - errcheck # - exhaustive - - exportloopref # - funlen # - gci # - gochecknoglobals diff --git a/conv/conv.go b/conv/conv.go index 099f67803..9a7f77ecc 100644 --- a/conv/conv.go +++ b/conv/conv.go @@ -194,13 +194,15 @@ func ToInt64(v interface{}) (int64, error) { case reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Int: return val.Int(), nil case reflect.Uint8, reflect.Uint16, reflect.Uint32: + //nolint:gosec // G115 is not applicable, we can safely convert these return int64(val.Uint()), nil case reflect.Uint, reflect.Uint64: - tv := val.Uint() + if !val.CanUint() { + return -1, fmt.Errorf("could not convert %v to int64", v) + } - // this can overflow and give -1, but IMO this is better than - // returning maxint64 - return int64(tv), nil + //nolint:gosec // G115 is not applicable, we already checked + return int64(val.Uint()), nil case reflect.Float32, reflect.Float64: return int64(val.Float()), nil case reflect.Bool: diff --git a/conv/evalargs.go b/conv/evalargs.go index b802e13de..f7df2ec1b 100644 --- a/conv/evalargs.go +++ b/conv/evalargs.go @@ -22,7 +22,7 @@ func printableValue(v reflect.Value) (interface{}, bool) { } if !v.Type().Implements(errorType) && !v.Type().Implements(fmtStringerType) { - if v.CanAddr() && (reflect.PtrTo(v.Type()).Implements(errorType) || reflect.PtrTo(v.Type()).Implements(fmtStringerType)) { + if v.CanAddr() && (reflect.PointerTo(v.Type()).Implements(errorType) || reflect.PointerTo(v.Type()).Implements(fmtStringerType)) { v = v.Addr() } else { switch v.Kind() {