From 5b16f9e4f28a5d1f5fb339756a177f13cc6eb32f Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Tue, 2 Apr 2024 14:42:10 +0900 Subject: [PATCH] Fix preference_get_string() function 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 --- preference/file-internal.cc | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/preference/file-internal.cc b/preference/file-internal.cc index cf250ed..a46ddc1 100644 --- a/preference/file-internal.cc +++ b/preference/file-internal.cc @@ -114,13 +114,8 @@ std::unique_ptr File::GetData() { Data::Type data_type = static_cast(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(&raw_data_[index]); data->SetString(str); -- 2.34.1