<p dir="auto">The following program crashes with panic:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="package main

import (
    &quot;fmt&quot;
    &quot;bytes&quot;
)

func main() {
    var a, b int
    r := bytes.NewReader([]byte{'1', '\n', '2'})

    _, err := fmt.Fscanf(r, &quot;%d&quot;, &amp;a)
    if err != nil {
        panic(err)
    }

    _, err = fmt.Fscanf(r, &quot;%d&quot;, &amp;b)
    if err != nil {
        panic(err)
    }
}"><pre class="notranslate"><code class="notranslate">package main

import (
    "fmt"
    "bytes"
)

func main() {
    var a, b int
    r := bytes.NewReader([]byte{'1', '\n', '2'})

    _, err := fmt.Fscanf(r, "%d", &amp;a)
    if err != nil {
        panic(err)
    }

    _, err = fmt.Fscanf(r, "%d", &amp;b)
    if err != nil {
        panic(err)
    }
}
</code></pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="panic: unexpected newline

goroutine 1 [running]:
main.main()
    /tmp/f.go:19 +0x33d
exit status 2"><pre class="notranslate"><code class="notranslate">panic: unexpected newline

goroutine 1 [running]:
main.main()
    /tmp/f.go:19 +0x33d
exit status 2
</code></pre></div>
<p dir="auto">on commit <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/golang/go/commit/b83b01110090c41fc24750ecabf0b87c5fbff233/hovercard" href="https://github.com/golang/go/commit/b83b01110090c41fc24750ecabf0b87c5fbff233"><tt>b83b011</tt></a></p>
<p dir="auto">I got different <code class="notranslate">fmt.Scanf</code> behavior depending on the line endings style.</p>
<p dir="auto">My go version is go1.3.3 darwin/amd64 on a Mac with OSX 10.10</p>
<p dir="auto">To reproduce the problem, here is a short go program:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="package main

import &quot;fmt&quot;

func main() {
    var steps, i int
    fmt.Scanf(&quot;%d&quot;, &amp;steps)

    var a, b int
    for i = 0; i &lt; steps; i++ {
        fmt.Scanf(&quot;%d&quot;, &amp;a)
        fmt.Scanf(&quot;%d&quot;, &amp;b)
        fmt.Println(a + b)
    }
}"><pre class="notranslate"><code class="notranslate">package main

import "fmt"

func main() {
    var steps, i int
    fmt.Scanf("%d", &amp;steps)

    var a, b int
    for i = 0; i &lt; steps; i++ {
        fmt.Scanf("%d", &amp;a)
        fmt.Scanf("%d", &amp;b)
        fmt.Println(a + b)
    }
}
</code></pre></div>
<p dir="auto">And an input file</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="2
2 5
4           8"><pre class="notranslate"><code class="notranslate">2
2 5
4           8
</code></pre></div>
<p dir="auto"><code class="notranslate">go run test.go &lt; input</code></p>
<p dir="auto">I expect to see regardless of the line endings been <code class="notranslate">\r\n</code> or <code class="notranslate">\n</code>:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="7
12"><pre class="notranslate"><code class="notranslate">7
12
</code></pre></div>
<p dir="auto">But I see</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="2
7"><pre class="notranslate"><code class="notranslate">2
7
</code></pre></div>
<p dir="auto">when in the input file the line endings are <code class="notranslate">\r\n</code> .</p>
<p dir="auto">If the line endings are <code class="notranslate">\n</code> it works fine.</p>