diff options
author | Nikias Bassen | 2014-09-20 01:03:33 +0200 |
---|---|---|
committer | Nikias Bassen | 2014-09-20 01:03:33 +0200 |
commit | 5ddbe5fa5ee011df10e288c405302a01e7c1dc71 (patch) | |
tree | 84e9be81b25271a8f6acf977b4a0c23aae8e5909 | |
parent | b6c43e901c1ee3ded15261621be1aaa090dab984 (diff) | |
download | libplist-5ddbe5fa5ee011df10e288c405302a01e7c1dc71.tar.gz libplist-5ddbe5fa5ee011df10e288c405302a01e7c1dc71.tar.bz2 |
C++: Make sure String::GetValue() and Key::GetValue() don't crash with NULL strings
-rw-r--r-- | src/Key.cpp | 9 | ||||
-rw-r--r-- | src/String.cpp | 9 |
2 files changed, 14 insertions, 4 deletions
diff --git a/src/Key.cpp b/src/Key.cpp index e3ccbe6..ed0c0c6 100644 --- a/src/Key.cpp +++ b/src/Key.cpp @@ -67,8 +67,13 @@ std::string Key::GetValue() const { char* s = NULL; plist_get_key_val(_node, &s); - std::string ret = s; - free(s); + std::string ret; + if (s) { + ret = s; + free(s); + } else { + ret = ""; + } return ret; } diff --git a/src/String.cpp b/src/String.cpp index 09b47b5..0965349 100644 --- a/src/String.cpp +++ b/src/String.cpp @@ -67,8 +67,13 @@ std::string String::GetValue() const { char* s = NULL; plist_get_string_val(_node, &s); - std::string ret = s; - free(s); + std::string ret; + if (s) { + ret = s; + free(s); + } else { + ret = ""; + } return ret; } |