Add string and symbol guard allocation paranoia

This commit is contained in:
Landon Curt Noll
2021-11-30 03:40:40 -08:00
parent d1d365d7ba
commit f3adb35e36
2 changed files with 50 additions and 22 deletions

View File

@@ -110,7 +110,7 @@ addglobal(char *name, BOOL isstatic)
return NULL;
hp = &globalhash[HASHSYM(name, len)];
for (sp = *hp; sp; sp = sp->g_next) {
if ((sp->g_len == len) && (strcmp(sp->g_name, name) == 0)
if ((sp->g_len == len) && (strncmp(sp->g_name, name, len+1) == 0)
&& (sp->g_filescope == newfilescope)
&& (sp->g_funcscope == newfuncscope))
return sp;
@@ -145,8 +145,8 @@ findglobal(char *name)
bestsp = NULL;
len = strlen(name);
for (sp = globalhash[HASHSYM(name, len)]; sp; sp = sp->g_next) {
if ((sp->g_len == len) && !strcmp(sp->g_name, name)) {
for (sp = globalhash[HASHSYM(name, len)]; sp != NULL; sp = sp->g_next) {
if ((sp->g_len == len) && (strncmp(sp->g_name, name, len+1) == 0)) {
if ((bestsp == NULL) ||
(sp->g_filescope > bestsp->g_filescope) ||
(sp->g_funcscope > bestsp->g_funcscope))