Commit 5da5e8e0 authored by Joel Sing's avatar Joel Sing

cmd/gc: check malloc return value

Check the return value from malloc - do not assume that we were
allocated memory just because we asked for it.

Update #4415.

R=minux.ma, daniel.morsing, remyoudompheng, rsc
CC=golang-dev
https://golang.org/cl/6782100
parent 73b3e230
...@@ -1165,6 +1165,11 @@ l0: ...@@ -1165,6 +1165,11 @@ l0:
case '[': case '[':
if(loophack || lstk != nil) { if(loophack || lstk != nil) {
h = malloc(sizeof *h); h = malloc(sizeof *h);
if(h == nil) {
flusherrors();
yyerror("out of memory");
errorexit();
}
h->v = loophack; h->v = loophack;
h->next = lstk; h->next = lstk;
lstk = h; lstk = h;
......
...@@ -84,6 +84,11 @@ init1(Node *n, NodeList **out) ...@@ -84,6 +84,11 @@ init1(Node *n, NodeList **out)
} }
n->initorder = InitPending; n->initorder = InitPending;
l = malloc(sizeof *l); l = malloc(sizeof *l);
if(l == nil) {
flusherrors();
yyerror("out of memory");
errorexit();
}
l->next = initlist; l->next = initlist;
l->n = n; l->n = n;
l->end = nil; l->end = nil;
......
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