mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-13 07:23:39 +00:00
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>
This commit is contained in:
+5
-1
@@ -954,7 +954,11 @@ func findPackagePath(path string, packagePathMap map[string]string) (packagePath
|
|||||||
libPath := strings.TrimPrefix(path, filepath.Join(goenv.Get("TINYGOROOT"), "lib")+string(os.PathSeparator))
|
libPath := strings.TrimPrefix(path, filepath.Join(goenv.Get("TINYGOROOT"), "lib")+string(os.PathSeparator))
|
||||||
parts := strings.SplitN(libPath, string(os.PathSeparator), 2)
|
parts := strings.SplitN(libPath, string(os.PathSeparator), 2)
|
||||||
packagePath = "C " + parts[0]
|
packagePath = "C " + parts[0]
|
||||||
filename = parts[1]
|
if len(parts) > 1 {
|
||||||
|
filename = parts[1]
|
||||||
|
} else {
|
||||||
|
filename = parts[0]
|
||||||
|
}
|
||||||
} else if prefix := filepath.Join(goenv.Get("TINYGOROOT"), "llvm-project", "compiler-rt"); strings.HasPrefix(path, prefix) {
|
} else if prefix := filepath.Join(goenv.Get("TINYGOROOT"), "llvm-project", "compiler-rt"); strings.HasPrefix(path, prefix) {
|
||||||
packagePath = "C compiler-rt"
|
packagePath = "C compiler-rt"
|
||||||
filename = strings.TrimPrefix(path, prefix+string(os.PathSeparator))
|
filename = strings.TrimPrefix(path, prefix+string(os.PathSeparator))
|
||||||
|
|||||||
Reference in New Issue
Block a user