cpp: Fix init of string from null
authorAndre Heinecke <aheinecke@intevation.de>
Fri, 14 Oct 2016 14:23:57 +0000 (16:23 +0200)
committerAndre Heinecke <aheinecke@intevation.de>
Fri, 14 Oct 2016 14:23:57 +0000 (16:23 +0200)
* lang/cpp/src/key.cpp (UserID::addrSpecFromString): Check return
value before creating the string.

lang/cpp/src/key.cpp

index 947405f..235a3c8 100644 (file)
@@ -884,9 +884,12 @@ std::string UserID::addrSpecFromString(const char *userid)
         return std::string();
     }
     char *normalized = gpgme_addrspec_from_uid (userid);
-    std::string ret(normalized);
-    gpgme_free(normalized);
-    return ret;
+    if (normalized) {
+        std::string ret(normalized);
+        gpgme_free(normalized);
+        return ret;
+    }
+    return std::string();
 }
 
 std::string UserID::addrSpec() const