Let's look at this code:
hash->vet = (lista**)calloc(tamanho, sizeof(lista*));
The hash->vet
will point to a memory area that contains a number of initially null pointers. This quantity is given by tamanho
.
Assuming that these pointers are not all overwritten with something else, this means that when accessing if(th->vet[i]->tamanho >= 0)
, if th->vet[i]
produces a null pointer, doing ->tamanho
will result in a segmentation fault. / p>
To know which solution is best, you would need to provide more information about the context in which the criaTabelaHash
and gerarRelatorioHash
functions are used. However, assuming that it is actually possible for th->vet[i]
to be null, a possible solution would be to change if
to look like this:
if (th->vet[i] && th->vet[i]->tamanho >= 0) {