summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2014-09-20 01:03:33 +0200
committerGravatar Nikias Bassen2014-09-20 01:03:33 +0200
commit5ddbe5fa5ee011df10e288c405302a01e7c1dc71 (patch)
tree84e9be81b25271a8f6acf977b4a0c23aae8e5909 /src
parentb6c43e901c1ee3ded15261621be1aaa090dab984 (diff)
downloadlibplist-5ddbe5fa5ee011df10e288c405302a01e7c1dc71.tar.gz
libplist-5ddbe5fa5ee011df10e288c405302a01e7c1dc71.tar.bz2
C++: Make sure String::GetValue() and Key::GetValue() don't crash with NULL strings
Diffstat (limited to 'src')
-rw-r--r--src/Key.cpp9
-rw-r--r--src/String.cpp9
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;
}