Fix preference_get_string() function 66/308866/1
authorHwankyu Jhun <h.jhun@samsung.com>
Tue, 2 Apr 2024 05:42:10 +0000 (14:42 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Tue, 2 Apr 2024 05:42:10 +0000 (14:42 +0900)
In the previous implementation, the preference does not write the data
if the string value is empty string. Even if the data length is 0, the
function should return the empty string.
This patch is for backward compatibility.

Change-Id: I36c9892cda0530fc3a2170e73c685958d188232b
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
preference/file-internal.cc

index cf250ed78d45ea5b1ad83964ec68e135293f8bb8..a46ddc186b5f81ac934bd4243f2bf525c3e718c9 100644 (file)
@@ -114,13 +114,8 @@ std::unique_ptr<Data> File::GetData() {
 
   Data::Type data_type = static_cast<Data::Type>(type);
   if (data_type == Data::Type::STRING) {
-    if (index == raw_data_.size())
-      return nullptr;
-
-    if (raw_data_[raw_data_.size() - 1] != '\0') {
-      _W("Last character is not a null-terminated string");
+    if (index == raw_data_.size() || raw_data_[raw_data_.size() - 1] != '\0')
       raw_data_.push_back(0x00);
-    }
 
     const char* str = reinterpret_cast<const char*>(&raw_data_[index]);
     data->SetString(str);