Patchwork [gccgo] Fix importing an archive

login
register
mail settings
Submitter Ian Taylor
Date Nov. 17, 2010, 12:22 a.m.
Message ID <mcrk4kc4x42.fsf@google.com>
Download mbox | patch
Permalink /patch/71488/
State New
Headers show

Comments

Ian Taylor - Nov. 17, 2010, 12:22 a.m.
When I switched gccgo to use the simple_object interface I forgot that
simple_object_start_read can change the file offset.  That broke reading
Go export data from an archive file.  This patch fixes it.  Committed to
gccgo branch.

Ian

Patch

diff -r 1cf52af24e94 go/import.cc
--- a/go/import.cc	Tue Nov 16 14:37:12 2010 -0800
+++ b/go/import.cc	Tue Nov 16 16:19:15 2010 -0800
@@ -192,6 +192,13 @@ 
 
   const int len = MAX(Export::v1_magic_len, Import::archive_magic_len);
 
+  if (lseek(fd, 0, SEEK_SET) < 0)
+    {
+      error_at(location, "lseek %s failed: %s", filename.c_str(),
+	       strerror(errno));
+      return NULL;
+    }
+
   char buf[len];
   ssize_t c = read(fd, buf, len);
   if (c < len)