Skip to content

Commit e98f778

Browse files
committed
builder: fix panic in findPackagePath when using -size short
This fixes an "index out of range" panic that occurs when calculating binary sizes. The strings.SplitN operation in findPackagePath can sometimes return a slice with only one element, so we now verify the length of the slice before attempting to access the second element. Signed-off-by: deadprogram <ron@hybridgroup.com>
1 parent a6c9ac6 commit e98f778

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

builder/sizes.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -954,7 +954,11 @@ func findPackagePath(path string, packagePathMap map[string]string) (packagePath
954954
libPath := strings.TrimPrefix(path, filepath.Join(goenv.Get("TINYGOROOT"), "lib")+string(os.PathSeparator))
955955
parts := strings.SplitN(libPath, string(os.PathSeparator), 2)
956956
packagePath = "C " + parts[0]
957-
filename = parts[1]
957+
if len(parts) > 1 {
958+
filename = parts[1]
959+
} else {
960+
filename = parts[0]
961+
}
958962
} else if prefix := filepath.Join(goenv.Get("TINYGOROOT"), "llvm-project", "compiler-rt"); strings.HasPrefix(path, prefix) {
959963
packagePath = "C compiler-rt"
960964
filename = strings.TrimPrefix(path, prefix+string(os.PathSeparator))

0 commit comments

Comments
 (0)