compiler: avoid undefined behavior in Import::read

For some implementations of Stream, advancing the stream will invalidate
the previously-returned peek buffer. Copy the peek buffer before
advancing in Import::read to avoid this undefined behavior.

Change-Id: Icfd56cf5e6f0d94a582d44e63bc51e75c24b8804
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/259438
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Trust: Than McIntosh <thanm@google.com>
3 files changed