]> git.ipfire.org Git - people/ms/libloc.git/commitdiff
perl: Fix lookup if given address is invalid or not in DB.
authorStefan Schantl <stefan.schantl@ipfire.org>
Wed, 2 Oct 2019 17:07:52 +0000 (19:07 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 3 Oct 2019 18:43:56 +0000 (18:43 +0000)
In this case now undef will be returned.

Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/perl/Location.xs

index ab27f0bf31866862cb0d3c54ae55896e5cc956e1..cdbc7e78387e07e621a33f78758b6cf50dd803d7 100644 (file)
@@ -92,27 +92,23 @@ get_license(db)
 #
 # Lookup functions
 #
-char*
+SV*
 lookup_country_code(db, address)
        struct loc_database* db;
        char* address;
 
        CODE:
+               RETVAL = &PL_sv_undef;
+
                // Lookup network
                struct loc_network *network;
                int err = loc_database_lookup_from_string(db, address, &network);
-               if (err) {
-                       croak("Could not look up for %s\n", address);
-               }
-
-               // Extract the country code
-               const char* country_code = loc_network_get_country_code(network);
-               loc_network_unref(network);
+               if (!err) {
+                       // Extract the country code
+                       const char* country_code = loc_network_get_country_code(network);
+                       RETVAL = newSVpv(country_code, strlen(country_code));
 
-               if (country_code) {
-                       RETVAL = strdup(country_code);
-               } else {
-                       RETVAL = NULL;
+                       loc_network_unref(network);
                }
        OUTPUT:
                RETVAL