Commit 53056c37 authored by Dmitriy Vyukov's avatar Dmitriy Vyukov

cmd/gc: fix heap buffer overflow

Fixes #8528.

LGTM=rsc
R=rsc, r, iant, bradfitz
CC=golang-codereviews
https://golang.org/cl/128230045
parent b3d5a695
...@@ -108,6 +108,9 @@ bvnext(Bvec *bv, int32 i) ...@@ -108,6 +108,9 @@ bvnext(Bvec *bv, int32 i)
{ {
uint32 w; uint32 w;
if(i >= bv->n)
return -1;
// Jump i ahead to next word with bits. // Jump i ahead to next word with bits.
if((bv->b[i>>WORDSHIFT]>>(i&WORDMASK)) == 0) { if((bv->b[i>>WORDSHIFT]>>(i&WORDMASK)) == 0) {
i &= ~WORDMASK; i &= ~WORDMASK;
...@@ -117,7 +120,7 @@ bvnext(Bvec *bv, int32 i) ...@@ -117,7 +120,7 @@ bvnext(Bvec *bv, int32 i)
} }
if(i >= bv->n) if(i >= bv->n)
return -1; return -1;
// Find 1 bit. // Find 1 bit.
w = bv->b[i>>WORDSHIFT]>>(i&WORDMASK); w = bv->b[i>>WORDSHIFT]>>(i&WORDMASK);
while((w&1) == 0) { while((w&1) == 0) {
......
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