Patchwork Go patch committed: Avoid endless loop inheriting interfaces

login
register
mail settings
Submitter Ian Taylor
Date Dec. 24, 2010, 12:13 a.m.
Message ID <mcr8vzgvxhp.fsf@google.com>
Download mbox | patch
Permalink /patch/76558/
State New
Headers show

Comments

Ian Taylor - Dec. 24, 2010, 12:13 a.m.
Invalid interface inheritance could send the Go frontend into an endless
loop.  This patch fixes it.  Bootstrapped and ran Go testsuite on
x86_64-unknown-linux-gnu.  Committed to mainline.

Ian

Patch

diff -r 7ad7ca0422a2 go/types.cc
--- a/go/types.cc	Wed Dec 22 17:34:50 2010 -0800
+++ b/go/types.cc	Thu Dec 23 16:10:10 2010 -0800
@@ -5548,7 +5548,7 @@ 
       const Typed_identifier* p = &this->methods_->at(from);
       if (!p->name().empty())
 	{
-	  size_t i = 0;
+	  size_t i;
 	  for (i = 0; i < to; ++i)
 	    {
 	      if (this->methods_->at(i).name() == p->name())
@@ -5594,7 +5594,30 @@ 
 	   q != methods->end();
 	   ++q)
 	{
-	  if (q->name().empty() || this->find_method(q->name()) == NULL)
+	  if (q->name().empty())
+	    {
+	      if (q->type() == p->type())
+		error_at(p->location(), "interface inheritance loop");
+	      else
+		{
+		  size_t i;
+		  for (i = from + 1; i < this->methods_->size(); ++i)
+		    {
+		      const Typed_identifier* r = &this->methods_->at(i);
+		      if (r->name().empty() && r->type() == q->type())
+			{
+			  error_at(p->location(),
+				   "inherited interface listed twice");
+			  break;
+			}
+		    }
+		  if (i == this->methods_->size())
+		    this->methods_->push_back(Typed_identifier(q->name(),
+							       q->type(),
+							       p->location()));
+		}
+	    }
+	  else if (this->find_method(q->name()) == NULL)
 	    this->methods_->push_back(Typed_identifier(q->name(), q->type(),
 						       p->location()));
 	  else