summaryrefslogtreecommitdiff
path: root/libgo/go/bytes
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2021-07-30 14:28:58 -0700
committerIan Lance Taylor <iant@golang.org>2021-08-12 20:23:07 -0700
commitc5b21c3f4c17b0649155035d2f9aa97b2da8a813 (patch)
treec6d3a68b503ba5b16182acbb958e3e5dbc95a43b /libgo/go/bytes
parent72be20e20299ec57b4bc9ba03d5b7d6bf10e97cc (diff)
downloadgcc-c5b21c3f4c17b0649155035d2f9aa97b2da8a813.tar.gz
libgo: update to Go1.17rc2
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/341629
Diffstat (limited to 'libgo/go/bytes')
-rw-r--r--libgo/go/bytes/boundary_test.go1
-rw-r--r--libgo/go/bytes/buffer.go3
-rw-r--r--libgo/go/bytes/buffer_test.go11
3 files changed, 14 insertions, 1 deletions
diff --git a/libgo/go/bytes/boundary_test.go b/libgo/go/bytes/boundary_test.go
index ea84f1e40fd..5a47526593b 100644
--- a/libgo/go/bytes/boundary_test.go
+++ b/libgo/go/bytes/boundary_test.go
@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//
+//go:build linux
// +build linux
package bytes_test
diff --git a/libgo/go/bytes/buffer.go b/libgo/go/bytes/buffer.go
index f19a4cfff09..549b077708f 100644
--- a/libgo/go/bytes/buffer.go
+++ b/libgo/go/bytes/buffer.go
@@ -275,7 +275,8 @@ func (b *Buffer) WriteByte(c byte) error {
// included to match bufio.Writer's WriteRune. The buffer is grown as needed;
// if it becomes too large, WriteRune will panic with ErrTooLarge.
func (b *Buffer) WriteRune(r rune) (n int, err error) {
- if r < utf8.RuneSelf {
+ // Compare as uint32 to correctly handle negative runes.
+ if uint32(r) < utf8.RuneSelf {
b.WriteByte(byte(r))
return 1, nil
}
diff --git a/libgo/go/bytes/buffer_test.go b/libgo/go/bytes/buffer_test.go
index fec5ef8a35f..9c9b7440ffa 100644
--- a/libgo/go/bytes/buffer_test.go
+++ b/libgo/go/bytes/buffer_test.go
@@ -6,6 +6,7 @@ package bytes_test
import (
. "bytes"
+ "fmt"
"io"
"math/rand"
"testing"
@@ -387,6 +388,16 @@ func TestRuneIO(t *testing.T) {
}
}
+func TestWriteInvalidRune(t *testing.T) {
+ // Invalid runes, including negative ones, should be written as
+ // utf8.RuneError.
+ for _, r := range []rune{-1, utf8.MaxRune + 1} {
+ var buf Buffer
+ buf.WriteRune(r)
+ check(t, fmt.Sprintf("TestWriteInvalidRune (%d)", r), &buf, "\uFFFD")
+ }
+}
+
func TestNext(t *testing.T) {
b := []byte{0, 1, 2, 3, 4}
tmp := make([]byte, 5)