diff --git a/src/src/example-synchronous.c b/src/src/example-synchronous.c index 513a3112..1b3f130f 100644 --- a/src/src/example-synchronous.c +++ b/src/src/example-synchronous.c @@ -43,7 +43,7 @@ int main() /* Be sure the search returned something */ uint32_t * this_error = NULL; 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); return(GETDNS_RETURN_GENERIC_ERROR); @@ -53,15 +53,17 @@ int main() size_t * num_addresses_ptr = NULL; this_ret = getdns_list_get_length(just_the_addresses_ptr, num_addresses_ptr); // Ignore any error /* Go through each record */ - 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 - /* Just print the address */ - struct getdns_bindata * 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)); - } + 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 + /* Just print the address */ + struct getdns_bindata * 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 */ getdns_context_destroy(this_context);