lundi 22 juillet 2019

check multi pointer redirection validation in C

I have a code where I am pointing to a nested sub structure element. Like:

struct bucket *hp = array->value.ht->pListHead;

I am getting the pListHead value. But Im wondering if there is chance of one of the pointer being NULL. One way of checking the validity of this redirection is to check each pointer like

if(array)
  if(array->value)
    if(array->value.ht)
      if(array->value.ht->pListHead)
        struct bucket *hp = array->value.ht->pListHead;

Is there any other solution of doing this validation ?

Aucun commentaire:

Enregistrer un commentaire