From 31316c4de692331ee1704430d5dd57ad72867ffd Mon Sep 17 00:00:00 2001 From: Tim Goh Date: Thu, 20 Sep 2012 15:46:40 +1000 Subject: [PATCH] Fix segfault when region_name returned by GeoIP is null --- geoip.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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));