Skip to content

bytes: Buffer.ReadBytes() does not advance the buffer #1498

@gopherbot

Description

@gopherbot

by joelegasse:

What steps will reproduce the problem?

Compiling and running the following program:

package main

import (
  "fmt"
  "bytes"
)

func main() {
  buf := bytes.NewBuffer([]byte{1, 2, 3, 4, 5})
  buf.ReadBytes(3)
  next,_ := buf.ReadByte()
  fmt.Println(next)
} 

What is the expected output?

"4" should be printed

What do you see instead?

"1" is printed

Which compiler are you using (5g, 6g, 8g, gccgo)?

6g

Which operating system are you using?

linux


Which revision are you using?  (hg identify)

867d37fb41a4 release.2011-02-01.1/release


Please provide any additional information below.

in src/pkg/bytes/buffer.go, right before the return for ReadBytes(), there should be the
line:

  b.off += size

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