From a02fc45dd31c0eab033e18387da9245ac5339c5c Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Tue, 16 Mar 2021 20:22:43 +0100 Subject: pkg/host: refactor getModulesInfo Use strconv.ParseUint instead of Sscanf, it's simpler for parsing of a single number. --- pkg/host/machine_info_linux.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'pkg/host/machine_info_linux.go') diff --git a/pkg/host/machine_info_linux.go b/pkg/host/machine_info_linux.go index eab2a1810..317d34cd9 100644 --- a/pkg/host/machine_info_linux.go +++ b/pkg/host/machine_info_linux.go @@ -11,6 +11,7 @@ import ( "os" "path/filepath" "regexp" + "strconv" "strings" ) @@ -124,14 +125,13 @@ func readKVMInfo(buffer *bytes.Buffer) error { } func getModulesInfo() ([]KernelModule, error) { - var addr uint64 var modules []KernelModule modulesText, _ := ioutil.ReadFile("/proc/modules") re := regexp.MustCompile(`(\w+) .*(0[x|X][a-fA-F0-9]+)[^\n]*`) - matches := re.FindAllSubmatch(modulesText, -1) - for _, m := range matches { - if _, err := fmt.Sscanf(strings.TrimPrefix(strings.ToLower(string(m[2])), "0x"), "%x", &addr); err != nil { - return nil, fmt.Errorf("address parsing error in /proc/modules") + for _, m := range re.FindAllSubmatch(modulesText, -1) { + addr, err := strconv.ParseUint(string(m[2]), 0, 64) + if err != nil { + return nil, fmt.Errorf("address parsing error in /proc/modules: %v", err) } modules = append(modules, KernelModule{ Name: string(m[1]), -- cgit mrf-deployment