Skip to content

bufio: uninitialised buffer in Writer causes panics and infinite loops #18211

@n10v

Description

@n10v

Please answer these questions before submitting your issue. Thanks!

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

go version go1.7.3 darwin/amd64

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

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/albert/go"
GORACE=""
GOROOT="/Users/albert/.gostable"
GOTOOLDIR="/Users/albert/.gostable/pkg/tool/darwin_amd64"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/wp/sytm29yd1d1dclmf01xgvqbw0000gn/T/go-build808633337=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"

What did you do?

If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.

If one will create buffer without using a constructor (buf := new(bufio.Writer)), then the further writes will cause panics or infinite loops depending on method one uses.
E.g. https://play.golang.org/p/LBrzU6xw2Z

What did you expect to see?

Buffer will be initialised, if it's not, and the further writes will be successful.

What did you see instead?

buf.WriteString causes an infinite loop: https://play.golang.org/p/LBrzU6xw2Z,
buf.WriteRune causes panic: https://play.golang.org/p/MAioIyqCJs,
buf.WriteByte causes panic: https://play.golang.org/p/e-JIMtF_tc,
and so on.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions