From: Michael Tremer Date: Thu, 30 Sep 2021 10:23:11 +0000 (+0000) Subject: country: Make country codes beginning with X invalid X-Git-Tag: 0.9.9~8 X-Git-Url: http://git.ipfire.org/?p=location%2Flibloc.git;a=commitdiff_plain;h=e8ebd079a59b6d3d854d080160594c3ff829ac42 country: Make country codes beginning with X invalid According to ISO3166, they are only allowed for "private use". Signed-off-by: Michael Tremer --- diff --git a/src/country.c b/src/country.c index 3ea04cc..0f13319 100644 --- a/src/country.c +++ b/src/country.c @@ -209,6 +209,10 @@ LOC_EXPORT int loc_country_code_is_valid(const char* cc) { return 0; } + // The code cannot begin with an X (those are reserved for private use) + if (*cc == 'X') + return 0; + // Looks valid return 1; } diff --git a/src/test-country.c b/src/test-country.c index fabdbc0..3e231ce 100644 --- a/src/test-country.c +++ b/src/test-country.c @@ -33,8 +33,8 @@ int main(int argc, char** argv) { int err; // Check some valid country codes - if (!loc_country_code_is_valid("XX")) { - fprintf(stderr, "Valid country code detected as invalid: %s\n", "XX"); + if (!loc_country_code_is_valid("DE")) { + fprintf(stderr, "Valid country code detected as invalid: %s\n", "DE"); exit(EXIT_FAILURE); } @@ -101,7 +101,7 @@ int main(int argc, char** argv) { exit(EXIT_FAILURE); // Create a country - err = loc_writer_add_country(writer, &country, "XX"); + err = loc_writer_add_country(writer, &country, "DE"); if (err) { fprintf(stderr, "Could not create country\n"); exit(EXIT_FAILURE); diff --git a/src/test-network.c b/src/test-network.c index daa844f..2a577c6 100644 --- a/src/test-network.c +++ b/src/test-network.c @@ -62,7 +62,7 @@ int main(int argc, char** argv) { exit(EXIT_FAILURE); } - err = loc_network_set_country_code(network1, "XX"); + err = loc_network_set_country_code(network1, "DE"); if (err) { fprintf(stderr, "Could not set country code\n"); exit(EXIT_FAILURE); @@ -113,7 +113,7 @@ int main(int argc, char** argv) { exit(EXIT_FAILURE); } - err = loc_network_set_country_code(network2, "XY"); + err = loc_network_set_country_code(network2, "DE"); if (err) { fprintf(stderr, "Could not set country code\n"); exit(EXIT_FAILURE);