From c2958ac74c65c138045daa60f149c5f9d949d743 Mon Sep 17 00:00:00 2001 From: Joel Hendrix Date: Thu, 27 Apr 2023 16:34:14 -0700 Subject: [PATCH] Remove undefined behavior during return (#723) --- autorest/utility.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/autorest/utility.go b/autorest/utility.go index 3467b8fa6..d35b3850a 100644 --- a/autorest/utility.go +++ b/autorest/utility.go @@ -60,9 +60,9 @@ func NewDecoder(encodedAs EncodedAs, r io.Reader) Decoder { // is especially useful if there is a chance the data will fail to decode. // encodedAs specifies the expected encoding, r provides the io.Reader to the data, and v // is the decoding destination. -func CopyAndDecode(encodedAs EncodedAs, r io.Reader, v interface{}) (bytes.Buffer, error) { - b := bytes.Buffer{} - return b, NewDecoder(encodedAs, io.TeeReader(r, &b)).Decode(v) +func CopyAndDecode(encodedAs EncodedAs, r io.Reader, v interface{}) (b bytes.Buffer, err error) { + err = NewDecoder(encodedAs, io.TeeReader(r, &b)).Decode(v) + return } // TeeReadCloser returns a ReadCloser that writes to w what it reads from rc.