Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/tools/go/analysis/passes/printf: panic analysing some wrong format pattern #54828

Closed
timonwong opened this issue Sep 2, 2022 · 3 comments
Closed
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@timonwong
Copy link

What version of Go are you using (go version)?

$ go version
go version go1.19 darwin/arm64

Does this issue reproduce with the latest release?

Yes.

What operating system and processor architecture are you using (go env)?

go env Output
$ go env

What did you do?

package main

import "fmt"

func main() {
	fmt.Printf("%[3]*.[2*[1]f", 1, 2, 3)
}

What did you expect to see?

The analyzer should shows error: "format has invalid argument index [2*[1]"

What did you see instead?

Panic:

panic: runtime error: slice bounds out of range [7:3]

goroutine 574 [running]:
golang.org/x/tools/go/analysis/passes/printf.(*formatState).parseIndex(0x14005d16d80)
        /Users/timonwong/Projects/Casual/go-x-tools/go/analysis/passes/printf/printf.go:682 +0x310
golang.org/x/tools/go/analysis/passes/printf.(*formatState).parsePrecision(0x14005d16d80)
        /Users/timonwong/Projects/Casual/go-x-tools/go/analysis/passes/printf/printf.go:717 +0xbc
golang.org/x/tools/go/analysis/passes/printf.parsePrintfVerb(0x140060600d0, 0x1400a30f780, {0x14005d32340, 0x8}, {0x14009edd8d1, 0xd}, 0x1, 0x1)
        /Users/timonwong/Projects/Casual/go-x-tools/go/analysis/passes/printf/printf.go:753 +0x3fc
golang.org/x/tools/go/analysis/passes/printf.checkPrintf(0x140060600d0?, 0x2, 0x1400a30f780, 0x1010621e8?)
        /Users/timonwong/Projects/Casual/go-x-tools/go/analysis/passes/printf/printf.go:592 +0x178
golang.org/x/tools/go/analysis/passes/printf.checkCall.func1({0x1011a5828?, 0x1400a30f780})
        /Users/timonwong/Projects/Casual/go-x-tools/go/analysis/passes/printf/printf.go:481 +0x68
golang.org/x/tools/go/ast/inspector.(*Inspector).Preorder(0x1400a294768, {0x14000297a28?, 0x1?, 0x140048ed880?}, 0x14009e53a38)
        /Users/timonwong/Projects/Casual/go-x-tools/go/ast/inspector/inspector.go:77 +0xa8
golang.org/x/tools/go/analysis/passes/printf.checkCall(0x140060600d0)
        /Users/timonwong/Projects/Casual/go-x-tools/go/analysis/passes/printf/printf.go:476 +0x90
golang.org/x/tools/go/analysis/passes/printf.run(0x101166bc0?)
        /Users/timonwong/Projects/Casual/go-x-tools/go/analysis/passes/printf/printf.go:141 +0x70
golang.org/x/tools/go/analysis/internal/checker.(*action).execOnce(0x14008532dc0)
        /Users/timonwong/Projects/Casual/go-x-tools/go/analysis/internal/checker/checker.go:731 +0x940
sync.(*Once).doSlow(0x14009e49f98?, 0x1010b8238?)
        /opt/homebrew/Cellar/go/1.19/libexec/src/sync/once.go:74 +0x104
sync.(*Once).Do(...)
        /opt/homebrew/Cellar/go/1.19/libexec/src/sync/once.go:65
golang.org/x/tools/go/analysis/internal/checker.(*action).exec(0x14009d90f78?)
        /Users/timonwong/Projects/Casual/go-x-tools/go/analysis/internal/checker/checker.go:619 +0x40
golang.org/x/tools/go/analysis/internal/checker.execAll.func1(0x0?)
        /Users/timonwong/Projects/Casual/go-x-tools/go/analysis/internal/checker/checker.go:607 +0x24
created by golang.org/x/tools/go/analysis/internal/checker.execAll
        /Users/timonwong/Projects/Casual/go-x-tools/go/analysis/internal/checker/checker.go:613 +0x168
@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label Sep 2, 2022
@gopherbot gopherbot added this to the Unreleased milestone Sep 2, 2022
@timonwong
Copy link
Author

I've submitted PR here: golang/tools#395

timonwong added a commit to timonwong/golang-tools that referenced this issue Sep 2, 2022
Fixes golang/go#54828

Signed-off-by: Timon Wong <timon86.wang@gmail.com>
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/426875 mentions this issue: go/analysis/passes/printf: fix panic parsing argument index

@heschi
Copy link
Contributor

heschi commented Sep 2, 2022

@heschi heschi added the NeedsFix The path to resolution is known, but the work has not been done. label Sep 2, 2022
timonwong added a commit to timonwong/golang-tools that referenced this issue Sep 7, 2022
Fixes golang/go#54828

Signed-off-by: Timon Wong <timon86.wang@gmail.com>
timonwong added a commit to timonwong/golang-tools that referenced this issue Sep 7, 2022
Fixes golang/go#54828

Signed-off-by: Timon Wong <timon86.wang@gmail.com>
@golang golang locked and limited conversation to collaborators Sep 7, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants