Skip to content

bytes: Reader.WriteTo returns EOF incorrectly #4421

@rsc

Description

@rsc
// WriteTo implements the io.WriterTo interface.
func (r *Reader) WriteTo(w io.Writer) (n int64, err error) {
    r.prevRune = -1
    if r.i >= len(r.s) {
        return 0, io.EOF
    }

The io.EOF should be nil. This breaks:

package main

import (
    "bytes"
    "log"
    "os/exec"
)

func main() {
    cmd := exec.Command("cat")
    cmd.Stdin = bytes.NewReader(nil)
    err := cmd.Run()
    if err != nil {
        log.Fatal(err)
    }
}

Obviously there are simpler tests.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions