Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix miss makezero bug #101

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

alingse
Copy link

@alingse alingse commented May 26, 2024

I was running github actions to run linter makezero for top github golang repos.

see issues alingse/go-linter-runner#1

and the github actions output https://github.com/alingse/go-linter-runner/actions/runs/9242680355/job/25425806374

====================================================================================================
append to slice `mountInfos` with non-zero initialized length at https://github.com/cdk-team/CDK/blob/main/pkg/util/cgroup.go#L130:16
append to slice `ret` with non-zero initialized length at https://github.com/cdk-team/CDK/blob/main/pkg/util/cgroup.go#L1[9](https://github.com/alingse/go-linter-runner/actions/runs/9242680355/job/25425806374#step:4:10)0:9
append to slice `sLst` with non-zero initialized length at https://github.com/cdk-team/CDK/blob/main/pkg/evaluate/cgroups.go#L40:[10](https://github.com/alingse/go-linter-runner/actions/runs/9242680355/job/25425806374#step:4:11)
====================================================================================================

the mountInfos and sLst is easy to check they are bugs , but ret is hard to fix, so I do not commit it.

// get kernel version
func GetKernelVersion() ([]int, error) {
	utsInfo := &unix.Utsname{}
	err := unix.Uname(utsInfo)
	if err != nil {
		return nil, err
	}
	relStr := string(utsInfo.Release[:])
	relIdx := strings.Index(relStr, "-")
	if relIdx == -1 {
		return nil, errors.New("unknown internal error when executing uname")
	}
	ret := make([]int, 3)
	for _, v := range strings.Split(relStr[:relIdx], ".") {
		verData, err := strconv.Atoi(v)
		if err != nil {
			return nil, err
		}
		ret = append(ret, verData)
	}
	return ret, nil
}

if we update ret := make([]int, 3) to ret := make([]int, 0, 3)

the GetKernelVersion may got ret with length less 3, if the user use index to operate it, may got some error, 🤔

so you can choose fix it or not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant