Patchwork Go patch committed: Don't crash if package import fails

login
register
mail settings
Submitter Ian Taylor
Date Jan. 4, 2011, 6:24 p.m.
Message ID <mcrsjx8plx3.fsf@google.com>
Download mbox | patch
Permalink /patch/77508/
State New
Headers show

Comments

Ian Taylor - Jan. 4, 2011, 6:24 p.m.
This patch to the Go frontend avoids crashing if importing a package
fails.  Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu.
Committed to mainline.

Ian

Patch

diff -r bc39dd879d69 go/gogo.cc
--- a/go/gogo.cc	Tue Jan 04 10:15:03 2011 -0800
+++ b/go/gogo.cc	Tue Jan 04 10:21:08 2011 -0800
@@ -330,8 +330,11 @@ 
   Import imp(stream, location);
   imp.register_builtin_types(this);
   Package* package = imp.import(this, local_name, is_local_name_exported);
-  this->imports_.insert(std::make_pair(filename, package));
-  package->set_is_imported();
+  if (package != NULL)
+    {
+      this->imports_.insert(std::make_pair(filename, package));
+      package->set_is_imported();
+    }
 
   delete stream;
 }