aboutsummaryrefslogtreecommitdiff
path: root/gcc/go
diff options
context:
space:
mode:
authorNikhil Benesch <nikhil.benesch@gmail.com>2020-10-04 02:03:36 -0400
committerIan Lance Taylor <iant@golang.org>2020-10-05 17:37:32 -0700
commit7164745e1c21ae85c52b727d61092ad0685b46e9 (patch)
tree7bdec0e840d3a7868cb172b7725a2689e434a1f5 /gcc/go
parent7e9282ae62f5318686dcd58498337090531cd6fc (diff)
downloadgcc-7164745e1c21ae85c52b727d61092ad0685b46e9.zip
gcc-7164745e1c21ae85c52b727d61092ad0685b46e9.tar.gz
gcc-7164745e1c21ae85c52b727d61092ad0685b46e9.tar.bz2
gofrontend: correct file reading logic in Stream_from_file
The implementation of Stream_from_file mishandled several cases: * It reversed the check for whether bytes were already available in the peek buffer. * It considered positive return values from lseek to be an error, when only a -1 return value indicates an error. Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/259437
Diffstat (limited to 'gcc/go')
-rw-r--r--gcc/go/gofrontend/MERGE2
-rw-r--r--gcc/go/gofrontend/import.cc8
2 files changed, 5 insertions, 5 deletions
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 9482740..701b2d42 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-801c458a562d22260ff176c26d65639dd32c8a90
+d00febdab0535546ccbf1ef634be1f23b09c8b77
The first line of this file holds the git revision number of the last
merge done from the gofrontend repository.
diff --git a/gcc/go/gofrontend/import.cc b/gcc/go/gofrontend/import.cc
index c63ae24..081afef 100644
--- a/gcc/go/gofrontend/import.cc
+++ b/gcc/go/gofrontend/import.cc
@@ -1487,7 +1487,7 @@ Stream_from_file::~Stream_from_file()
bool
Stream_from_file::do_peek(size_t length, const char** bytes)
{
- if (this->data_.length() <= length)
+ if (this->data_.length() >= length)
{
*bytes = this->data_.data();
return true;
@@ -1504,7 +1504,7 @@ Stream_from_file::do_peek(size_t length, const char** bytes)
return false;
}
- if (lseek(this->fd_, - got, SEEK_CUR) != 0)
+ if (lseek(this->fd_, - got, SEEK_CUR) < 0)
{
if (!this->saw_error())
go_fatal_error(Linemap::unknown_location(), "lseek failed: %m");
@@ -1524,7 +1524,7 @@ Stream_from_file::do_peek(size_t length, const char** bytes)
void
Stream_from_file::do_advance(size_t skip)
{
- if (lseek(this->fd_, skip, SEEK_CUR) != 0)
+ if (lseek(this->fd_, skip, SEEK_CUR) < 0)
{
if (!this->saw_error())
go_fatal_error(Linemap::unknown_location(), "lseek failed: %m");
@@ -1532,7 +1532,7 @@ Stream_from_file::do_advance(size_t skip)
}
if (!this->data_.empty())
{
- if (this->data_.length() < skip)
+ if (this->data_.length() > skip)
this->data_.erase(0, skip);
else
this->data_.clear();