libct: fix errorlint warning about strconv.NumError

This one is tough as errorlint insists on using errors.Is, and the
latter is known to not work for Go 1.13 which we still support.

So, add a nolint annotation to suppress the warning, and a TODO to
address it later.

For intelrdt, we can do the same, but it is easier to reuse the very
same function from fscommon (note we can't use fscommon for other stuff
as it expects cgroupfs).

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
Kir Kolyshkin
2021-06-08 20:51:08 -07:00
parent 7be93a66b9
commit adbac31d88
2 changed files with 6 additions and 20 deletions
+4 -1
View File
@@ -45,7 +45,10 @@ func ParseUint(s string, base, bitSize int) (uint64, error) {
// 2. Handle negative values lesser than MinInt64
if intErr == nil && intValue < 0 {
return 0, nil
} else if intErr != nil && intErr.(*strconv.NumError).Err == strconv.ErrRange && intValue < 0 {
// Note errors.Is is not working for strconv errors in Go 1.13,
// see https://github.com/golang/go/issues/36325.
// TODO: remove nolint and switch to errors.Is once we stop supporting Go 1.13.
} else if intErr != nil && intErr.(*strconv.NumError).Err == strconv.ErrRange && intValue < 0 { //nolint:errorlint
return 0, nil
}
+2 -19
View File
@@ -15,6 +15,7 @@ import (
"sync"
"github.com/moby/sys/mountinfo"
"github.com/opencontainers/runc/libcontainer/cgroups/fscommon"
"github.com/opencontainers/runc/libcontainer/configs"
)
@@ -366,24 +367,6 @@ func parseCpuInfoFile(path string) (cpuInfoFlags, error) {
return infoFlags, nil
}
func parseUint(s string, base, bitSize int) (uint64, error) {
value, err := strconv.ParseUint(s, base, bitSize)
if err != nil {
intValue, intErr := strconv.ParseInt(s, base, bitSize)
// 1. Handle negative values greater than MinInt64 (and)
// 2. Handle negative values lesser than MinInt64
if intErr == nil && intValue < 0 {
return 0, nil
} else if intErr != nil && intErr.(*strconv.NumError).Err == strconv.ErrRange && intValue < 0 {
return 0, nil
}
return value, err
}
return value, nil
}
// Gets a single uint64 value from the specified file.
func getIntelRdtParamUint(path, file string) (uint64, error) {
fileName := filepath.Join(path, file)
@@ -392,7 +375,7 @@ func getIntelRdtParamUint(path, file string) (uint64, error) {
return 0, err
}
res, err := parseUint(string(bytes.TrimSpace(contents)), 10, 64)
res, err := fscommon.ParseUint(string(bytes.TrimSpace(contents)), 10, 64)
if err != nil {
return res, fmt.Errorf("unable to parse %q as a uint from file %q", string(contents), fileName)
}