mirror of
https://github.com/golang/go.git
synced 2026-06-27 19:30:52 +00:00
cmd/compile: add missing bound checks when handle zero-sized values
Fixes #79197 Change-Id: Ifded6ec4c014d2e87dab7b66c8063f8ffa66be5d Reviewed-on: https://go-review.googlesource.com/c/go/+/774120 LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Keith Randall <khr@golang.org> Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: David Chase <drchase@google.com>
This commit is contained in:
parent
e929fb78e4
commit
6f19c3b459
2 changed files with 43 additions and 0 deletions
|
|
@ -4549,6 +4549,8 @@ func (s *state) assignWhichMayOverlap(left ir.Node, right *ssa.Value, deref bool
|
|||
return
|
||||
}
|
||||
if t.Size() == 0 {
|
||||
len := s.constInt(types.Types[types.TINT], n)
|
||||
s.boundsCheck(i, len, ssa.BoundsIndex, false)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
|||
41
test/fixedbugs/issue79197.go
Normal file
41
test/fixedbugs/issue79197.go
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
// run
|
||||
|
||||
// Copyright 2026 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package main
|
||||
|
||||
//go:noinline
|
||||
func a1(i int) {
|
||||
var a [1]struct{}
|
||||
a[i] = struct{}{}
|
||||
}
|
||||
|
||||
//go:noinline
|
||||
func a2(i int) {
|
||||
var a [1][0]int
|
||||
a[i] = [0]int{}
|
||||
}
|
||||
|
||||
//go:noinline
|
||||
func a3(i int) {
|
||||
var a [1]struct{ x [0]int }
|
||||
a[i] = struct{ x [0]int }{}
|
||||
}
|
||||
|
||||
func wantPanic(name string, f func()) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
return
|
||||
}
|
||||
panic(name + ": no panic (bug)")
|
||||
}()
|
||||
f()
|
||||
}
|
||||
|
||||
func main() {
|
||||
wantPanic("a1", func() { a1(5) })
|
||||
wantPanic("a2", func() { a2(5) })
|
||||
wantPanic("a3", func() { a3(5) })
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue