1
0
mirror of https://github.com/golang/go synced 2024-11-26 11:08:38 -07:00

cmd/cc, cmd/ld: do not overflow strings in symbol lookup.

R=golang-dev, dave, minux.ma
CC=golang-dev
https://golang.org/cl/7876044
This commit is contained in:
Rémy Oudompheng 2013-03-25 08:20:22 +01:00
parent 3add0fef1e
commit 77e7e4c329
2 changed files with 3 additions and 4 deletions

View File

@ -263,7 +263,7 @@ lookup(void)
for(s = hash[h]; s != S; s = s->link) {
if(s->name[0] != c)
continue;
if(memcmp(s->name, symb, l) == 0)
if(strcmp(s->name, symb) == 0)
return s;
}
s = alloc(sizeof(*s));

View File

@ -846,17 +846,16 @@ _lookup(char *symb, int v, int creat)
Sym *s;
char *p;
int32 h;
int l, c;
int c;
h = v;
for(p=symb; c = *p; p++)
h = h+h+h + c;
l = (p - symb) + 1;
// not if(h < 0) h = ~h, because gcc 4.3 -O2 miscompiles it.
h &= 0xffffff;
h %= NHASH;
for(s = hash[h]; s != S; s = s->hash)
if(memcmp(s->name, symb, l) == 0)
if(strcmp(s->name, symb) == 0)
return s;
if(!creat)
return nil;