Skip to content

Conversation

@mayooot
Copy link

@mayooot mayooot commented Aug 8, 2024

The code to be modified is below, when theType length is 0, will be panic.

// Only get in when the function is defined for a structure. Global functions are not needed for class diagram
theType, _ := getFieldType(decl.Recv.List[0].Type, p.allImports)
theType = replacePackageConstant(theType, "")
if theType[0] == "*"[0] {
theType = theType[1:]
}

error:

panic: runtime error: index out of range [0] with length 0

goroutine 1 [running]:
github.com/jfeliu007/goplantuml/parser.(*ClassParser).handleFuncDecl(0xc00007a0a0, 0xc000167740)
 /Users/ming/Desktop/goplantuml/parser/class_parser.go:279 +0x3cd
github.com/jfeliu007/goplantuml/parser.(*ClassParser).parseFileDeclarations(0xc00007a0a0?, {0x60eae8?, 0xc000167740?})
 /Users/ming/Desktop/goplantuml/parser/class_parser.go:265 +0x72
github.com/jfeliu007/goplantuml/parser.(*ClassParser).parsePackage(0xc00007a0a0, {0x60de20?, 0xc000172ae0})
 /Users/ming/Desktop/goplantuml/parser/class_parser.go:233 +0x353
github.com/jfeliu007/goplantuml/parser.(*ClassParser).parseDirectory(0xc00007a0a0, {0x7ffd1a0c813f, 0x2f})
 /Users/ming/Desktop/goplantuml/parser/class_parser.go:254 +0xd4
github.com/jfeliu007/goplantuml/parser.NewClassDiagramWithOptions.func1({0x7ffd1a0c813f, 0x2f}, {0x60fc08, 0xc00007f2b0}, {0x0?, 0x0?})
 /Users/ming/Desktop/goplantuml/parser/class_parser.go:169 +0x105
github.com/spf13/afero.walk({0x610920, 0x79b860}, {0x7ffd1a0c813f, 0x2f}, {0x60fc08, 0xc00007f2b0}, 0xc00017bc00)
 /Users/ming/Desktop/goplantuml/vendor/github.com/spf13/afero/path.go:44 +0x6c
github.com/spf13/afero.Walk({0x610920, 0x79b860}, {0x7ffd1a0c813f, 0x2f}, 0xc000104c00)
 /Users/ming/Desktop/goplantuml/vendor/github.com/spf13/afero/path.go:105 +0x7a
github.com/jfeliu007/goplantuml/parser.NewClassDiagramWithOptions(0xc00017bc30)
 /Users/ming/Desktop/goplantuml/parser/class_parser.go:158 +0x2d0
github.com/jfeliu007/goplantuml/parser.NewClassDiagram({0xc00002a220?, 0xc000104f00?, 0x8?}, {0x79b860?, 0x0?, 0x1f?}, 0x47?)
 /Users/ming/Desktop/goplantuml/parser/class_parser.go:209 +0x8d
main.main()
 /Users/ming/Desktop/goplantuml/cmd/goplantuml/main.go:102 +0xd69

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