Commit ce99bb2c authored by Rémy Oudompheng's avatar Rémy Oudompheng

cmd/gc: fix nil pointer dereferences.

Fixes #5119.

R=golang-dev, dvyukov, dave, rsc
CC=golang-dev
https://golang.org/cl/7838050
parent d7434816
...@@ -1339,6 +1339,8 @@ addmethod(Sym *sf, Type *t, int local, int nointerface) ...@@ -1339,6 +1339,8 @@ addmethod(Sym *sf, Type *t, int local, int nointerface)
f = methtype(pa, 1); f = methtype(pa, 1);
if(f == T) { if(f == T) {
t = pa; t = pa;
if(t == T) // rely on typecheck having complained before
return;
if(t != T) { if(t != T) {
if(isptr[t->etype]) { if(isptr[t->etype]) {
if(t->sym != S) { if(t->sym != S) {
...@@ -1347,10 +1349,8 @@ addmethod(Sym *sf, Type *t, int local, int nointerface) ...@@ -1347,10 +1349,8 @@ addmethod(Sym *sf, Type *t, int local, int nointerface)
} }
t = t->type; t = t->type;
} }
} if(t->broke) // rely on typecheck having complained before
if(t->broke) // rely on typecheck having complained before return;
return;
if(t != T) {
if(t->sym == S) { if(t->sym == S) {
yyerror("invalid receiver type %T (%T is an unnamed type)", pa, t); yyerror("invalid receiver type %T (%T is an unnamed type)", pa, t);
return; return;
......
...@@ -714,6 +714,12 @@ methcmp(const void *va, const void *vb) ...@@ -714,6 +714,12 @@ methcmp(const void *va, const void *vb)
a = *(Type**)va; a = *(Type**)va;
b = *(Type**)vb; b = *(Type**)vb;
if(a->sym == S && b->sym == S)
return 0;
if(a->sym == S)
return -1;
if(b->sym == S)
return 1;
i = strcmp(a->sym->name, b->sym->name); i = strcmp(a->sym->name, b->sym->name);
if(i != 0) if(i != 0)
return i; return i;
...@@ -1393,7 +1399,7 @@ assignconv(Node *n, Type *t, char *context) ...@@ -1393,7 +1399,7 @@ assignconv(Node *n, Type *t, char *context)
Node *r, *old; Node *r, *old;
char *why; char *why;
if(n == N || n->type == T) if(n == N || n->type == T || n->type->broke)
return n; return n;
old = n; old = n;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment