diff options
author | 2025-02-24 23:01:20 +0800 | |
---|---|---|
committer | 2025-03-01 23:17:04 +0100 | |
commit | 02be84957d44ce68dcf81bada0d3250d4d81395a (patch) | |
tree | 9a74cbe22aced4c2b410ce883fb2834144399085 /src/String.cpp | |
parent | 44099d4b79c8d6a7d599d652ebef62db8dae6696 (diff) | |
download | libplist-02be84957d44ce68dcf81bada0d3250d4d81395a.tar.gz libplist-02be84957d44ce68dcf81bada0d3250d4d81395a.tar.bz2 |
C++: Fix String::GetValue memory leaking and suport assignment of const char*
Diffstat (limited to 'src/String.cpp')
-rw-r--r-- | src/String.cpp | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/String.cpp b/src/String.cpp index 2ddc28b..326aa7f 100644 --- a/src/String.cpp +++ b/src/String.cpp @@ -45,6 +45,13 @@ String& String::operator=(const PList::String& s) return *this; } +String& String::operator=(const char* s) +{ + plist_free(_node); + _node = plist_new_string(s); + return *this; +} + String::String(const std::string& s) : Node(PLIST_STRING) { plist_set_string_val(_node, s.c_str()); @@ -66,10 +73,8 @@ void String::SetValue(const std::string& s) std::string String::GetValue() const { - char* s = NULL; - plist_get_string_val(_node, &s); + const char* s = plist_get_string_ptr(_node, NULL); std::string ret = s ? s : ""; - delete s; return ret; } |