cgroups: force 64 bits to ParseUint

[NO TESTS NEEDED]

force bitsSize==64 so that the string is always parsed to a uint64
instead of using the native int size, that could be not big enough on
32 bits arches.

Closes: https://github.com/containers/podman/issues/9979

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
Giuseppe Scrivano 2021-04-09 10:07:46 +02:00
parent 4efac1f760
commit ce747466a9
No known key found for this signature in database
GPG key ID: E4730F97F60286ED
2 changed files with 5 additions and 5 deletions

View file

@ -265,7 +265,7 @@ func readFileAsUint64(path string) (uint64, error) {
if v == "max" {
return math.MaxUint64, nil
}
ret, err := strconv.ParseUint(v, 10, 0)
ret, err := strconv.ParseUint(v, 10, 64)
if err != nil {
return ret, errors.Wrapf(err, "parse %s from %s", v, path)
}

View file

@ -40,7 +40,7 @@ func readAcctList(ctr *CgroupControl, name string) ([]uint64, error) {
if s == "" {
break
}
v, err := strconv.ParseUint(s, 10, 0)
v, err := strconv.ParseUint(s, 10, 64)
if err != nil {
return nil, errors.Wrapf(err, "parsing %s", s)
}
@ -80,14 +80,14 @@ func (c *cpuHandler) Stat(ctr *CgroupControl, m *Metrics) error {
return err
}
if val, found := values["usage_usec"]; found {
usage.Total, err = strconv.ParseUint(cleanString(val[0]), 10, 0)
usage.Total, err = strconv.ParseUint(cleanString(val[0]), 10, 64)
if err != nil {
return err
}
usage.Kernel *= 1000
}
if val, found := values["system_usec"]; found {
usage.Kernel, err = strconv.ParseUint(cleanString(val[0]), 10, 0)
usage.Kernel, err = strconv.ParseUint(cleanString(val[0]), 10, 64)
if err != nil {
return err
}
@ -149,7 +149,7 @@ func GetSystemCPUUsage() (uint64, error) {
}
if val, found := values["usage_usec"]; found {
v, err := strconv.ParseUint(cleanString(val[0]), 10, 0)
v, err := strconv.ParseUint(cleanString(val[0]), 10, 64)
if err != nil {
return 0, err
}