OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [testsuite/] [go.test/] [test/] [fixedbugs/] [bug303.go] - Blame information for rev 700

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 700 jeremybenn
// $G $D/$F.go && $L $F.$A && ./$A.out
2
 
3
// Copyright 2010 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
// Issue 1011.  Removing either #1 or #3 avoided the crash at #2.
8
 
9
package main
10
 
11
import (
12
        "io"
13
        "strings"
14
)
15
 
16
func readU16BE(b []byte) uint16 {
17
        b[0] = 0
18
        b[1] = 1
19
        return uint16(b[0])<<8 + uint16(b[1]) // #1
20
        n := uint16(b[0])<<8 + uint16(b[1])
21
        return n
22
}
23
 
24
func readStr(r io.Reader, b []byte) string {
25
        n := readU16BE(b)
26
        if int(n) > len(b) {
27
                return "err: n>b"
28
        }
29
        io.ReadFull(r, b[0:n]) // #2
30
        return string(b[0:n])  // #3
31
        return "ok"
32
}
33
 
34
func main() {
35
        br := strings.NewReader("abcd")
36
        readStr(br, make([]byte, 256))
37
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.