]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/gc: avoid writing past end of region array
authorRuss Cox <rsc@golang.org>
Fri, 13 Feb 2015 16:54:15 +0000 (11:54 -0500)
committerRuss Cox <rsc@golang.org>
Fri, 13 Feb 2015 17:30:05 +0000 (17:30 +0000)
Noticed last week.
Just saw a strange build failure in the revised rcmp (called by qsort on region)
and this fixed it.

Submitting first to avoid finding out which of my pending CLs tickled the
problem.

Change-Id: I4cafd611e2bf8e813e57ad0025e48bde5ae54359
Reviewed-on: https://go-review.googlesource.com/4830
Reviewed-by: Russ Cox <rsc@golang.org>
src/cmd/gc/reg.c

index a60e71cfb75796154930bb9c7e8b48f044704019..f4a88505a62fb470756b7962ef03a817653dafa5 100644 (file)
@@ -351,21 +351,21 @@ loop2:
                        bit.b[z] = LOAD(r) & ~(r->act.b[z] | addrs.b[z]);
                while(bany(&bit)) {
                        i = bnum(bit);
-                       rgp->enter = f;
-                       rgp->varno = i;
                        change = 0;
                        paint1(f, i);
                        biclr(&bit, i);
                        if(change <= 0)
                                continue;
-                       rgp->cost = change;
-                       nregion++;
                        if(nregion >= NRGN) {
                                if(debug['R'] && debug['v'])
                                        print("too many regions\n");
                                goto brk;
                        }
+                       rgp->enter = f;
+                       rgp->varno = i;
+                       rgp->cost = change;
                        rgp++;
+                       nregion++;
                }
        }
 brk: