diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2021-03-16 20:22:43 +0100 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2021-03-18 09:17:51 +0100 |
| commit | a02fc45dd31c0eab033e18387da9245ac5339c5c (patch) | |
| tree | 97c9106e0c285dcf5c83ee9cee1436d20887778e /pkg/host/machine_info_linux.go | |
| parent | 8d4d5838fe0a51500959c0c10f4040a1369043c2 (diff) | |
pkg/host: refactor getModulesInfo
Use strconv.ParseUint instead of Sscanf, it's simpler
for parsing of a single number.
Diffstat (limited to 'pkg/host/machine_info_linux.go')
| -rw-r--r-- | pkg/host/machine_info_linux.go | 10 |
1 files changed, 5 insertions, 5 deletions
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]), |
