Fixed a couple of null pointer problems

There were two null pointers causing it to dump core.  I realize the
code doesn't actually do anything, but still.
This commit is contained in:
Melinda Shore 2013-06-16 18:00:54 -08:00
parent b3ed4429d6
commit 096d4e5b77
1 changed files with 12 additions and 10 deletions

View File

@ -43,7 +43,7 @@ int main()
/* Be sure the search returned something */ /* Be sure the search returned something */
uint32_t * this_error = NULL; uint32_t * this_error = NULL;
this_ret = getdns_dict_get_int(this_response, "status", this_error); // Ignore any error this_ret = getdns_dict_get_int(this_response, "status", this_error); // Ignore any error
if (*this_error != GETDNS_RESPSTATUS_GOOD) // If the search didn't return "good" if (this_error && (*this_error != GETDNS_RESPSTATUS_GOOD)) // If the search didn't return "good"
{ {
fprintf(stderr, "The search had no results, and a return value of %d. Exiting.", *this_error); fprintf(stderr, "The search had no results, and a return value of %d. Exiting.", *this_error);
return(GETDNS_RETURN_GENERIC_ERROR); return(GETDNS_RETURN_GENERIC_ERROR);
@ -53,15 +53,17 @@ int main()
size_t * num_addresses_ptr = NULL; size_t * num_addresses_ptr = NULL;
this_ret = getdns_list_get_length(just_the_addresses_ptr, num_addresses_ptr); // Ignore any error this_ret = getdns_list_get_length(just_the_addresses_ptr, num_addresses_ptr); // Ignore any error
/* Go through each record */ /* Go through each record */
for ( size_t rec_count = 0; rec_count <= *num_addresses_ptr; ++rec_count ) if (num_addresses_ptr) {
{ for ( size_t rec_count = 0; rec_count <= *num_addresses_ptr; ++rec_count )
struct getdns_dict * this_address; {
this_ret = getdns_list_get_dict(just_the_addresses_ptr, rec_count, &this_address); // Ignore any error struct getdns_dict * this_address;
/* Just print the address */ this_ret = getdns_list_get_dict(just_the_addresses_ptr, rec_count, &this_address); // Ignore any error
struct getdns_bindata * this_address_data; /* Just print the address */
this_ret = getdns_dict_get_bindata(this_address, "address_data", &this_address_data); // Ignore any error struct getdns_bindata * this_address_data;
printf("The address is %s", getdns_display_ip_address(this_address_data)); this_ret = getdns_dict_get_bindata(this_address, "address_data", &this_address_data); // Ignore any error
} printf("The address is %s", getdns_display_ip_address(this_address_data));
}
}
} }
/* Clean up */ /* Clean up */
getdns_context_destroy(this_context); getdns_context_destroy(this_context);