unsigned int
hash(const char *str)
{
unsigned int hash = 5381;
int c;
int i;
size_t k= strlen(str)*1;
char *str2=malloc(k+1);
strcpy(str2,str);
for(i=0;i<strlen(str);i++)
{
if(isalpha(str[i]))
str2[i]=tolower(str2[i]);
}
while ((c = *str2++))
hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
free(str2);
return hash%143090;
}
This is the Djb2 hash function with a slight modification for case insensitivity. Valgrind shows the error "Invalid write of size 1" at strcpy.