File tree Expand file tree Collapse file tree 4 files changed +97
-0
lines changed Expand file tree Collapse file tree 4 files changed +97
-0
lines changed Original file line number Diff line number Diff line change
1
+ // Copyright 2019 The Go Authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style
3
+ // license that can be found in the LICENSE file.
4
+
5
+ package a
6
+
7
+ import (
8
+ "errors"
9
+ "strings"
10
+ )
11
+
12
+ var G interface {}
13
+
14
+ func Unmarshal (data []byte , o interface {}) error {
15
+ G = o
16
+ v , ok := o .(* map [string ]interface {})
17
+ if ! ok {
18
+ return errors .New ("eek" )
19
+ }
20
+ vals := make (map [string ]interface {})
21
+ s := string (data )
22
+ items := strings .Split (s , " " )
23
+ var err error
24
+ for _ , item := range items {
25
+ vals [item ] = s
26
+ if item == "error" {
27
+ err = errors .New ("ouch" )
28
+ }
29
+ }
30
+ * v = vals
31
+ return err
32
+ }
Original file line number Diff line number Diff line change
1
+ // Copyright 2019 The Go Authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style
3
+ // license that can be found in the LICENSE file.
4
+
5
+ package b
6
+
7
+ import (
8
+ "io/ioutil"
9
+
10
+ "./a"
11
+ )
12
+
13
+ var G int
14
+
15
+ // An inlinable function. To trigger the bug in question this needs
16
+ // to be inlined here within the package and also inlined into some
17
+ // other package that imports it.
18
+ func ReadValues (data []byte ) (vals map [string ]interface {}, err error ) {
19
+ err = a .Unmarshal (data , & vals )
20
+ if len (vals ) == 0 {
21
+ vals = map [string ]interface {}{}
22
+ }
23
+ return
24
+ }
25
+
26
+ // A local call to the function above, which triggers the "move to heap"
27
+ // of the output param.
28
+ func CallReadValues (filename string ) (map [string ]interface {}, error ) {
29
+ defer func () { G ++ }()
30
+ data , err := ioutil .ReadFile (filename )
31
+ if err != nil {
32
+ return map [string ]interface {}{}, err
33
+ }
34
+ return ReadValues (data )
35
+ }
Original file line number Diff line number Diff line change
1
+ // Copyright 2019 The Go Authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style
3
+ // license that can be found in the LICENSE file.
4
+
5
+ package main
6
+
7
+ import (
8
+ "os"
9
+
10
+ "./b"
11
+ )
12
+
13
+ func main () {
14
+ seed := "some things are better"
15
+ bsl := []byte (seed )
16
+ b .CallReadValues ("/dev/null" )
17
+ vals , err := b .ReadValues (bsl )
18
+ if vals ["better" ] != seed || err != nil {
19
+ os .Exit (1 )
20
+ }
21
+ }
Original file line number Diff line number Diff line change
1
+ // rundir -P -l=4 -ldflags -strictdups=2
2
+
3
+ // Copyright 2019 The Go Authors. All rights reserved.
4
+ // Use of this source code is governed by a BSD-style
5
+ // license that can be found in the LICENSE file.
6
+
7
+ // +build !nacl,!js
8
+
9
+ package ignored
You can’t perform that action at this time.
0 commit comments