From e491c6eea9ad599a0ae766a3217bd9a16ca3a25a Mon Sep 17 00:00:00 2001 From: Katie Hockman Date: Wed, 27 Jan 2021 10:33:35 -0500 Subject: math/big: fix comment in divRecursiveStep There appears to be a typo in the description of the recursive division algorithm. Two things seem suspicious with the original comment: 1. It is talking about choosing s, but s doesn't appear anywhere in the equation. 2. The math in the equation is incorrect. Where B = len(v)/2 s = B - 1 Proof that it is incorrect: len(v) - B >= B + 1 len(v) - len(v)/2 >= len(v)/2 + 1 This doesn't hold if len(v) is even, e.g. 10: 10 - 10/2 >= 10/2 + 1 10 - 5 >= 5 + 1 5 >= 6 // this is false The new equation will be the following, which will be mathematically correct: len(v) - s >= B + 1 len(v) - (len(v)/2 - 1) >= len(v)/2 + 1 len(v) - len(v)/2 + 1 >= len(v)/2 + 1 len(v) - len(v)/2 >= len(v)/2 This holds if len(v) is even or odd. e.g. 10 10 - 10/2 >= 10/2 10 - 5 >= 5 5 >= 5 e.g. 11 11 - 11/2 >= 11/2 11 - 5 >= 5 6 >= 5 Change-Id: If77ce09286cf7038637b5dfd0fb7d4f828023f56 Reviewed-on: https://go-review.googlesource.com/c/go/+/287372 Run-TryBot: Katie Hockman Reviewed-by: Filippo Valsorda Trust: Katie Hockman --- src/math/big/nat.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/math/big/nat.go b/src/math/big/nat.go index 068176e1c1..bbd6c8850b 100644 --- a/src/math/big/nat.go +++ b/src/math/big/nat.go @@ -881,7 +881,7 @@ func (z nat) divRecursiveStep(u, v nat, depth int, tmp *nat, temps []*nat) { // then floor(u1/v1) >= floor(u/v) // // Moreover, the difference is at most 2 if len(v1) >= len(u/v) - // We choose s = B-1 since len(v)-B >= B+1 >= len(u/v) + // We choose s = B-1 since len(v)-s >= B+1 >= len(u/v) s := (B - 1) // Except for the first step, the top bits are always // a division remainder, so the quotient length is <= n. -- cgit v1.2.3-54-g00ecf From 8869086d8f0a31033ccdc103106c768dc17216b1 Mon Sep 17 00:00:00 2001 From: Ikko Ashimine Date: Thu, 4 Feb 2021 02:47:37 +0000 Subject: runtime: fix typo in histogram.go indicies -> indices Change-Id: Ia50ae5918fc7a53c23590a94a18087a99bfd9bb7 GitHub-Last-Rev: 98eb724275fd61d5f5ce5dad6b1010c10f76906d GitHub-Pull-Request: golang/go#44095 Reviewed-on: https://go-review.googlesource.com/c/go/+/289529 Reviewed-by: Ian Lance Taylor Trust: Keith Randall --- src/runtime/histogram.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/runtime/histogram.go b/src/runtime/histogram.go index 42baa6c5e2..da4910d341 100644 --- a/src/runtime/histogram.go +++ b/src/runtime/histogram.go @@ -26,7 +26,7 @@ const ( // The number of super-buckets (timeHistNumSuperBuckets), on the // other hand, defines the range. To reserve room for sub-buckets, // bit timeHistSubBucketBits is the first bit considered for - // super-buckets, so super-bucket indicies are adjusted accordingly. + // super-buckets, so super-bucket indices are adjusted accordingly. // // As an example, consider 45 super-buckets with 16 sub-buckets. // -- cgit v1.2.3-54-g00ecf From 4516afebedd18692c6dc70cbdee16a049c26024b Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Fri, 5 Feb 2021 10:55:12 -0500 Subject: testing/fstest: avoid symlink-induced failures in tester Do not require directory entry and Stat result to match for symlinks, because they won't (Stat dereferences the symlink). Fixes #44113. Change-Id: Ifc6dbce5719906e2f42254a7172f1ef787464a9e Reviewed-on: https://go-review.googlesource.com/c/go/+/290009 Trust: Russ Cox Run-TryBot: Russ Cox Reviewed-by: Bryan C. Mills --- src/testing/fstest/testfs.go | 25 ++++++++++++++++++------- src/testing/fstest/testfs_test.go | 31 +++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 7 deletions(-) create mode 100644 src/testing/fstest/testfs_test.go diff --git a/src/testing/fstest/testfs.go b/src/testing/fstest/testfs.go index a7f8007333..8fc8acaaf3 100644 --- a/src/testing/fstest/testfs.go +++ b/src/testing/fstest/testfs.go @@ -403,9 +403,10 @@ func (t *fsTester) checkStat(path string, entry fs.DirEntry) { return } fentry := formatEntry(entry) - finfo := formatInfoEntry(info) - if fentry != finfo { - t.errorf("%s: mismatch:\n\tentry = %s\n\tfile.Stat() = %s", path, fentry, finfo) + fientry := formatInfoEntry(info) + // Note: mismatch here is OK for symlink, because Open dereferences symlink. + if fentry != fientry && entry.Type()&fs.ModeSymlink == 0 { + t.errorf("%s: mismatch:\n\tentry = %s\n\tfile.Stat() = %s", path, fentry, fientry) } einfo, err := entry.Info() @@ -413,12 +414,22 @@ func (t *fsTester) checkStat(path string, entry fs.DirEntry) { t.errorf("%s: entry.Info: %v", path, err) return } - fentry = formatInfo(einfo) - finfo = formatInfo(info) - if fentry != finfo { - t.errorf("%s: mismatch:\n\tentry.Info() = %s\n\tfile.Stat() = %s\n", path, fentry, finfo) + finfo := formatInfo(info) + if entry.Type()&fs.ModeSymlink != 0 { + // For symlink, just check that entry.Info matches entry on common fields. + // Open deferences symlink, so info itself may differ. + feentry := formatInfoEntry(einfo) + if fentry != feentry { + t.errorf("%s: mismatch\n\tentry = %s\n\tentry.Info() = %s\n", path, fentry, feentry) + } + } else { + feinfo := formatInfo(einfo) + if feinfo != finfo { + t.errorf("%s: mismatch:\n\tentry.Info() = %s\n\tfile.Stat() = %s\n", path, feinfo, finfo) + } } + // Stat should be the same as Open+Stat, even for symlinks. info2, err := fs.Stat(t.fsys, path) if err != nil { t.errorf("%s: fs.Stat: %v", path, err) diff --git a/src/testing/fstest/testfs_test.go b/src/testing/fstest/testfs_test.go new file mode 100644 index 0000000000..5b8813c343 --- /dev/null +++ b/src/testing/fstest/testfs_test.go @@ -0,0 +1,31 @@ +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package fstest + +import ( + "internal/testenv" + "os" + "path/filepath" + "testing" +) + +func TestSymlink(t *testing.T) { + testenv.MustHaveSymlink(t) + + tmp := t.TempDir() + tmpfs := os.DirFS(tmp) + + if err := os.WriteFile(filepath.Join(tmp, "hello"), []byte("hello, world\n"), 0644); err != nil { + t.Fatal(err) + } + + if err := os.Symlink(filepath.Join(tmp, "hello"), filepath.Join(tmp, "hello.link")); err != nil { + t.Fatal(err) + } + + if err := TestFS(tmpfs, "hello", "hello.link"); err != nil { + t.Fatal(err) + } +} -- cgit v1.2.3-54-g00ecf From b54cd94d478c95e79e5eea1d77e73d7b2b769f09 Mon Sep 17 00:00:00 2001 From: Jay Conrod Date: Fri, 5 Feb 2021 16:45:40 -0500 Subject: embed, io/fs: clarify that leading and trailing slashes are disallowed Fixes #44012 Change-Id: I5782cea301a65ae12ba870ff1e6b2e0a2651dc09 Reviewed-on: https://go-review.googlesource.com/c/go/+/290071 Run-TryBot: Jay Conrod Reviewed-by: Bryan C. Mills TryBot-Result: Go Bot Trust: Jay Conrod --- src/embed/embed.go | 18 +++++++++--------- src/io/fs/fs.go | 1 + 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/embed/embed.go b/src/embed/embed.go index f12bf31e76..98da870ac6 100644 --- a/src/embed/embed.go +++ b/src/embed/embed.go @@ -61,12 +61,15 @@ // The Go build system will recognize the directives and arrange for the declared variable // (in the example above, content) to be populated with the matching files from the file system. // -// The //go:embed directive accepts multiple space-separated patterns for brevity, -// but it can also be repeated, to avoid very long lines when there are many patterns. -// The patterns are interpreted relative to the package directory containing the source file. -// The path separator is a forward slash, even on Windows systems. -// To allow for naming files with spaces in their names, patterns can be written -// as Go double-quoted or back-quoted string literals. +// The //go:embed directive accepts multiple space-separated patterns for +// brevity, but it can also be repeated, to avoid very long lines when there are +// many patterns. The patterns are interpreted relative to the package directory +// containing the source file. The path separator is a forward slash, even on +// Windows systems. Patterns may not contain ‘.’ or ‘..’ or empty path elements, +// nor may they begin or end with a slash. To match everything in the current +// directory, use ‘*’ instead of ‘.’. To allow for naming files with spaces in +// their names, patterns can be written as Go double-quoted or back-quoted +// string literals. // // If a pattern names a directory, all files in the subtree rooted at that directory are // embedded (recursively), except that files with names beginning with ‘.’ or ‘_’ @@ -87,9 +90,6 @@ // Matches for empty directories are ignored. After that, each pattern in a //go:embed line // must match at least one file or non-empty directory. // -// Patterns must not contain ‘.’ or ‘..’ path elements nor begin with a leading slash. -// To match everything in the current directory, use ‘*’ instead of ‘.’. -// // If any patterns are invalid or have invalid matches, the build will fail. // // Strings and Bytes diff --git a/src/io/fs/fs.go b/src/io/fs/fs.go index b691a86049..c330f123ad 100644 --- a/src/io/fs/fs.go +++ b/src/io/fs/fs.go @@ -36,6 +36,7 @@ type FS interface { // sequences of path elements, like “x/y/z”. // Path names must not contain a “.” or “..” or empty element, // except for the special case that the root directory is named “.”. +// Leading and trailing slashes (like “/x” or “x/”) are not allowed. // // Paths are slash-separated on all systems, even Windows. // Backslashes must not appear in path names. -- cgit v1.2.3-54-g00ecf From 724d0720b3e110f64598bf789cbe2a6a1b3b0fd8 Mon Sep 17 00:00:00 2001 From: KimMachineGun Date: Fri, 5 Feb 2021 05:47:46 +0000 Subject: doc/go1.16: add missed heading tag in vet section Add missed heading tag in CL 276373. For #40700 Change-Id: Ida9e8861589bbc296a5a1cecbf9fe33fa09ed0ca GitHub-Last-Rev: d218f8d4b70b20c30422863db7bed3683e3218e6 GitHub-Pull-Request: golang/go#44111 Reviewed-on: https://go-review.googlesource.com/c/go/+/289869 Reviewed-by: Tim King Reviewed-by: Dmitri Shuralyov Trust: Tim King Trust: Dmitri Shuralyov --- doc/go1.16.html | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/go1.16.html b/doc/go1.16.html index 8d31f63fa2..878bf0d029 100644 --- a/doc/go1.16.html +++ b/doc/go1.16.html @@ -364,6 +364,8 @@ func TestFoo(t *testing.T) { } +

New warning for frame pointer

+

The vet tool now warns about amd64 assembly that clobbers the BP register (the frame pointer) without saving and restoring it, -- cgit v1.2.3-54-g00ecf From ed3e4afa12d655a0c5606bcf3dd4e1cdadcb1476 Mon Sep 17 00:00:00 2001 From: Ori Bernstein Date: Wed, 6 Jan 2021 02:40:05 +0000 Subject: syscall/plan9: remove spooky fd action at a distance Change Plan 9 fork/exec to use the O_CLOEXEC file descriptor, instead of relying on spooky at a distance. Historically, Plan 9 has set the O_CLOEXEC flag on the underlying channels in the kernel, rather than the file descriptors -- if two fds pointed at a single channel, as with dup, changing the flags on one of them would be observable on the other. The per-Chan semantics are ok, if unexpected, when a chan is only handled within a single process, but this isn't always the case. Forked processes share Chans, but even more of a problem is the interaction between /srv and OCEXEC, which can lead to unexectedly closed file descriptors in completely unrelated proceses. For example: func exists() bool { // If some other thread execs here, // we don't want to leak the fd, so // open it O_CLOEXEC fd := Open("/srv/foo", O_CLOEXEC) if fd != -1 { Close(fd) return true } return false } would close the connection to any file descriptor (maybe even for the root fs) in ALL other processes that have it open if an exec were to happen(!), which is quite undesriable. As a result, 9front will be changing this behavior for the next release. Go is the only code observed so far that relies on this behavior on purpose, and It's easy to make the code work with both semantics: simply using the file descriptor that was opened with O_CEXEC instead of throwing it away. So we do that here. Fixes #43524 Change-Id: I4887f5c934a5e63e5e6c1bb59878a325abc928d3 GitHub-Last-Rev: 96bb21bd1e8f64dc7e082a56928748a7d54c9272 GitHub-Pull-Request: golang/go#43533 Reviewed-on: https://go-review.googlesource.com/c/go/+/281833 Reviewed-by: David du Colombier <0intro@gmail.com> Reviewed-by: Richard Miller Reviewed-by: Jacob Moody Run-TryBot: David du Colombier <0intro@gmail.com> Trust: Ian Lance Taylor --- src/syscall/exec_plan9.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/syscall/exec_plan9.go b/src/syscall/exec_plan9.go index 47ccbdc384..12c4237f69 100644 --- a/src/syscall/exec_plan9.go +++ b/src/syscall/exec_plan9.go @@ -320,14 +320,15 @@ func cexecPipe(p []int) error { return e } - fd, e := Open("#d/"+itoa(p[1]), O_CLOEXEC) + fd, e := Open("#d/"+itoa(p[1]), O_RDWR|O_CLOEXEC) if e != nil { Close(p[0]) Close(p[1]) return e } - Close(fd) + Close(p[1]) + p[1] = fd return nil } -- cgit v1.2.3-54-g00ecf From 1901853098bbe25a1bbedc0ee53c6658d754151e Mon Sep 17 00:00:00 2001 From: Changkun Ou Date: Sun, 7 Feb 2021 17:31:12 +0100 Subject: runtime/metrics: fix panic in readingAllMetric example medianBucket can return if the total is greater than thresh. However, if a histogram has no counts, total and thresh will both be zero and cause panic. Adding an equal sign to prevent the potential panic. Fixes #44148 Change-Id: Ifb8a781990f490d142ae7c035b4e01d6a07ae04d Reviewed-on: https://go-review.googlesource.com/c/go/+/290171 Trust: Ian Lance Taylor Reviewed-by: Michael Knyszek Run-TryBot: Michael Knyszek TryBot-Result: Go Bot --- src/runtime/metrics/example_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/runtime/metrics/example_test.go b/src/runtime/metrics/example_test.go index cade0c38bf..624d9d8a6b 100644 --- a/src/runtime/metrics/example_test.go +++ b/src/runtime/metrics/example_test.go @@ -88,7 +88,7 @@ func medianBucket(h *metrics.Float64Histogram) float64 { total = 0 for i, count := range h.Counts { total += count - if total > thresh { + if total >= thresh { return h.Buckets[i] } } -- cgit v1.2.3-54-g00ecf