Skip to content

Commit

Permalink
Safer operation on variant string
Browse files Browse the repository at this point in the history
Signed-off-by: Chongyi Zheng <git@zcy.dev>
  • Loading branch information
harryzcy committed Jun 27, 2024
1 parent 0cdbb8b commit a924c4b
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,11 @@ func platformVector(platform specs.Platform) []specs.Platform {
variant = "v8"
}

if armMajor, err := strconv.Atoi(strings.TrimPrefix(variant[:2], "v")); err == nil && armMajor >= 8 {
majorVariant, minorVariant, hasMinor := strings.Cut(variant, ".") // v8.0 -> v8
if armMajor, err := strconv.Atoi(strings.TrimPrefix(majorVariant, "v")); err == nil && armMajor >= 8 {
armMinor := 0
if len(variant) == 4 {
if minor, err := strconv.Atoi(variant[3:]); err == nil && variant[2] == '.' {
if minor, err := strconv.Atoi(minorVariant); err == nil && hasMinor {
armMinor = minor
}
}
Expand Down

0 comments on commit a924c4b

Please sign in to comment.