Skip to content

Commit

Permalink
Fix slice append error
Browse files Browse the repository at this point in the history
In golang when copy a slice, if the slice is initialized with a
desired length, then appending to it will cause the size double.

Signed-off-by: bin liu <liubin0329@gmail.com>
(cherry picked from commit 0c63c42)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
  • Loading branch information
liubin authored and thaJeztah committed Jan 24, 2023
1 parent cf13b64 commit e6cf5ec
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pkg/cri/server/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ func copyResourcesToStatus(spec *runtimespec.Spec, status containerstore.Status)
}

if spec.Linux.Resources.HugepageLimits != nil {
hugepageLimits := make([]*runtime.HugepageLimit, len(spec.Linux.Resources.HugepageLimits))
hugepageLimits := make([]*runtime.HugepageLimit, 0)
for _, l := range spec.Linux.Resources.HugepageLimits {
hugepageLimits = append(hugepageLimits, &runtime.HugepageLimit{
PageSize: l.Pagesize,
Expand Down
2 changes: 1 addition & 1 deletion pkg/cri/store/container/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func deepCopyOf(s Status) Status {
}
copy.Resources = &runtime.ContainerResources{}
if s.Resources != nil && s.Resources.Linux != nil {
hugepageLimits := make([]*runtime.HugepageLimit, len(s.Resources.Linux.HugepageLimits))
hugepageLimits := make([]*runtime.HugepageLimit, 0)
for _, l := range s.Resources.Linux.HugepageLimits {
if l != nil {
hugepageLimits = append(hugepageLimits, &runtime.HugepageLimit{
Expand Down

0 comments on commit e6cf5ec

Please sign in to comment.