Fix an out-of-bounds array access when formatting some empty comment

This commit is contained in:
Mickael Carl 2025-03-06 23:31:09 +00:00
parent 5b5bcd566a
commit 6d83c91d49
3 changed files with 5 additions and 1 deletions

View File

@ -0,0 +1,2 @@
//
{}

View File

@ -0,0 +1,2 @@
#
{}

View File

@ -38,7 +38,7 @@ func (c *EnforceCommentStyle) FodderElement(p pass.ASTPass, element *ast.FodderE
*comment = "#" + (*comment)[2:]
}
if c.Options.CommentStyle == CommentStyleSlash && (*comment)[0] == '#' {
if !c.seenFirstFodder && (*comment)[1] == '!' {
if !c.seenFirstFodder && len(*comment) > 1 && (*comment)[1] == '!' {
return
}
*comment = "//" + (*comment)[1:]