Skip to content

Commit

Permalink
bugfix: s/TrimRight/TrimSuffix for certain cases
Browse files Browse the repository at this point in the history
Use `TrimSuffix` instead of `TrimRight` in cases where an exact suffix
string needs to be removed, not all occurrences of all characters in a
specified cutset.

Fixes: #507

Signed-off-by: Pranshu Srivastava <[email protected]>
  • Loading branch information
rexagod committed Mar 21, 2024
1 parent f7c2619 commit 680ecde
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions buddyinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ func parseBuddyInfo(r io.Reader) ([]BuddyInfo, error) {
return nil, fmt.Errorf("%w: Invalid number of fields, found: %v", ErrFileParse, parts)
}

node := strings.TrimRight(parts[1], ",")
zone := strings.TrimRight(parts[3], ",")
node := strings.TrimSuffix(parts[1], ",")
zone := strings.TrimSuffix(parts[3], ",")
arraySize := len(parts[4:])

if bucketCount == -1 {
Expand Down
2 changes: 1 addition & 1 deletion proc.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func (p Proc) CmdLine() ([]string, error) {
return []string{}, nil
}

return strings.Split(string(bytes.TrimRight(data, string("\x00"))), string(byte(0))), nil
return strings.Split(string(bytes.TrimRight(data, "\x00")), "\x00"), nil
}

// Wchan returns the wchan (wait channel) of a process.
Expand Down
2 changes: 1 addition & 1 deletion proc_smaps.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func (s *ProcSMapsRollup) parseLine(line string) error {
}

v := strings.TrimSpace(kv[1])
v = strings.TrimRight(v, " kB")
v = strings.TrimSuffix(v, " kB")

vKBytes, err := strconv.ParseUint(v, 10, 64)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion sysfs/system_cpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ func parseCPURange(data []byte) ([]uint16, error) {

var cpusInt = []uint16{}

for _, cpu := range strings.Split(strings.TrimRight(string(data), "\n"), ",") {
for _, cpu := range strings.Split(strings.TrimSuffix(string(data), "\n"), ",") {
if cpu == "" {
continue
}
Expand Down

0 comments on commit 680ecde

Please sign in to comment.