Skip to content

Commit 6d83c91

Browse files
committed
Fix an out-of-bounds array access when formatting some empty comment
1 parent 5b5bcd5 commit 6d83c91

File tree

3 files changed

+5
-1
lines changed

3 files changed

+5
-1
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
//
2+
{}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#
2+
{}

internal/formatter/enforce_comment_style.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func (c *EnforceCommentStyle) FodderElement(p pass.ASTPass, element *ast.FodderE
3838
*comment = "#" + (*comment)[2:]
3939
}
4040
if c.Options.CommentStyle == CommentStyleSlash && (*comment)[0] == '#' {
41-
if !c.seenFirstFodder && (*comment)[1] == '!' {
41+
if !c.seenFirstFodder && len(*comment) > 1 && (*comment)[1] == '!' {
4242
return
4343
}
4444
*comment = "//" + (*comment)[1:]

0 commit comments

Comments
 (0)