]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/gc: avoid infinite recursion on invalid recursive type
authorRuss Cox <rsc@golang.org>
Thu, 25 Sep 2014 17:08:37 +0000 (13:08 -0400)
committerRuss Cox <rsc@golang.org>
Thu, 25 Sep 2014 17:08:37 +0000 (13:08 -0400)
Fixes #8507.

LGTM=iant
R=golang-codereviews, iant
CC=golang-codereviews, r
https://golang.org/cl/144560043

src/cmd/gc/align.c
src/cmd/gc/subr.c
test/fixedbugs/issue8507.go [new file with mode: 0644]

index b809640e4227a71b610c4489039185a3e06f410b..6e5d149c750829b675f2262cbb375b43835bcfb5 100644 (file)
@@ -119,8 +119,10 @@ dowidth(Type *t)
        if(t->width == -2) {
                lno = lineno;
                lineno = t->lineno;
-               if(!t->broke)
+               if(!t->broke) {
+                       t->broke = 1;
                        yyerror("invalid recursive type %T", t);
+               }
                t->width = 0;
                lineno = lno;
                return;
index 666be9667923a1b03103796f721cd7047bff83dd..c3bc5af3b8d888c98bbf0f96980c279f02b111fa 100644 (file)
@@ -529,7 +529,8 @@ algtype1(Type *t, Type **bad)
        
        if(bad)
                *bad = T;
-
+       if(t->broke)
+               return AMEM;
        if(t->noalg)
                return ANOEQ;
 
diff --git a/test/fixedbugs/issue8507.go b/test/fixedbugs/issue8507.go
new file mode 100644 (file)
index 0000000..00a14aa
--- /dev/null
@@ -0,0 +1,16 @@
+// errorcheck
+
+// Copyright 2014 The Go Authors.  All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// issue 8507
+// used to call algtype on invalid recursive type and get into infinite recursion
+
+package p
+
+type T struct{ T } // ERROR "invalid recursive type T"
+
+func f() {
+       println(T{} == T{})
+}