From: Hwankyu Jhun Date: Mon, 4 Mar 2024 02:14:04 +0000 (+0900) Subject: Fix string getter implementation X-Git-Tag: accepted/tizen/unified/20240304.123104~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6dc3992d8d5097d9c997f514e0d6a4cc83fc7d83;p=platform%2Fcore%2Fapi%2Fpreference.git Fix string getter implementation In the previous implementation, the file does not have the null-terminated string if the data is string type. After refactored the implementation, the file has the null-terminated string. The preference API checks whether the last character is the null-terminated string or not. And, if it's not, the null-terminated string will be added. This patch is for backward compatibility. Change-Id: Ia0a50d008be7f66616410c80d98b963dc36e68ad Signed-off-by: Hwankyu Jhun --- diff --git a/preference/file-internal.cc b/preference/file-internal.cc index b32e832..cf250ed 100644 --- a/preference/file-internal.cc +++ b/preference/file-internal.cc @@ -117,6 +117,11 @@ std::unique_ptr File::GetData() { if (index == raw_data_.size()) return nullptr; + if (raw_data_[raw_data_.size() - 1] != '\0') { + _W("Last character is not a null-terminated string"); + raw_data_.push_back(0x00); + } + const char* str = reinterpret_cast(&raw_data_[index]); data->SetString(str); } else if (data_type == Data::Type::INT) {