OK. 
We now have 3 instead of 2 cases to deal with
1) Key not found in the repository
2) Key exists in repository but is not allocated to a zone (e.g. a generated key). We can't calculate the keytag, but we still need to correctly report that it is in the repository. So add a separate check for this case and don't print the key tag.
3) Else, key exists and has a zone name so fall into the else clause as below. 

Something like:

  if (!key) {
    printf("%-33s %s NOT IN repository\n", temp_loc, temp_hsm);
  else {
     if (temp_zone == NULL) {
       printf("%-33s %s\n", temp_loc, temp_hsm);
    } else {
        sign_params = hsm_sign_params_new();
...