diff --git a/geoip.c b/geoip.c index 085f6e1..186545e 100644 --- a/geoip.c +++ b/geoip.c @@ -117,6 +117,7 @@ static VALUE generic_single_value_lookup_response(char *key, char *value) VALUE rb_city_record_to_hash(GeoIPRecord *record) { VALUE hash = rb_hash_new(); + const char *region_name; if(record->country_code) rb_hash_sset(hash, "country_code", encode_to_utf8_and_return_rb_str(record->country_code)); @@ -126,7 +127,8 @@ VALUE rb_city_record_to_hash(GeoIPRecord *record) rb_hash_sset(hash, "country_name", encode_to_utf8_and_return_rb_str(record->country_name)); if(record->region) { rb_hash_sset(hash, "region", encode_to_utf8_and_return_rb_str(record->region)); - rb_hash_sset(hash, "region_name", encode_to_utf8_and_return_rb_str(GeoIP_region_name_by_code(record->country_code, record->region))); + if(region_name = GeoIP_region_name_by_code(record->country_code, record->region)) + rb_hash_sset(hash, "region_name", encode_to_utf8_and_return_rb_str(region_name)); } if(record->city) rb_hash_sset(hash, "city", encode_to_utf8_and_return_rb_str(record->city));