From 7c2718b12a33180b3f6099e321c25af35c67f6fd Mon Sep 17 00:00:00 2001 From: Rob Pike Date: Mon, 22 Oct 2018 14:04:18 +1100 Subject: [PATCH] doc: tweak example in Effective Go A prior attempt at addressing the issue got bogged down in an endless conversation around the subtleties of Read semantics. Let's not go there. Instead, we put the issue to bed, perhaps not in perfect comfort but well enough, by moving a line of the example so that even if there is a "benign" error as the issue suggests, the loop terminates with n and err correctly set. Fixes #27818 Change-Id: I4a32d56c9e782f17578565d90b22ce531e3d8667 Reviewed-on: https://go-review.googlesource.com/c/143677 Reviewed-by: Ian Lance Taylor --- doc/effective_go.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/effective_go.html b/doc/effective_go.html index 89c1d08782..38d09f4c73 100644 --- a/doc/effective_go.html +++ b/doc/effective_go.html @@ -1402,11 +1402,11 @@ the moment, the following snippet would also read the first 32 bytes of the buff var err error for i := 0; i < 32; i++ { nbytes, e := f.Read(buf[i:i+1]) // Read one byte. + n += nbytes if nbytes == 0 || e != nil { err = e break } - n += nbytes }

-- 2.50.0