diff --git a/services/distributeddataservice/service/kvdb/kvdb_observer_proxy.cpp b/services/distributeddataservice/service/kvdb/kvdb_observer_proxy.cpp index 3eb5413ef7a34faf0fed0d8d53f6ca6723bd4b87..e2bdbae6a69c372b2973d499cc6906245c177eac 100644 --- a/services/distributeddataservice/service/kvdb/kvdb_observer_proxy.cpp +++ b/services/distributeddataservice/service/kvdb/kvdb_observer_proxy.cpp @@ -47,8 +47,8 @@ void KVDBObserverProxy::OnChange(const ChangeNotification &changeNotification) int64_t insertSize = ITypesUtil::GetTotalSize(changeNotification.GetInsertEntries()); int64_t updateSize = ITypesUtil::GetTotalSize(changeNotification.GetUpdateEntries()); int64_t deleteSize = ITypesUtil::GetTotalSize(changeNotification.GetDeleteEntries()); - int64_t totalSize = insertSize + updateSize + deleteSize + sizeof(uint32_t); - if (insertSize < 0 || updateSize < 0 || deleteSize < 0 || !data.WriteInt32(totalSize)) { + int64_t totalSize = insertSize + updateSize + deleteSize; + if (insertSize < 0 || updateSize < 0 || deleteSize < 0 || !data.WriteInt64(totalSize)) { ZLOGE("Write ChangeNotification buffer size to parcel failed."); return; } @@ -59,10 +59,24 @@ void KVDBObserverProxy::OnChange(const ChangeNotification &changeNotification) return; } } else { - if (!ITypesUtil::Marshal(data, changeNotification.GetDeviceId(), uint32_t(changeNotification.IsClear())) || - !ITypesUtil::MarshalToBuffer(changeNotification.GetInsertEntries(), insertSize, data) || - !ITypesUtil::MarshalToBuffer(changeNotification.GetUpdateEntries(), updateSize, data) || - !ITypesUtil::MarshalToBuffer(changeNotification.GetDeleteEntries(), deleteSize, data)) { + if (!ITypesUtil::Marshal(data, changeNotification.GetDeviceId(), uint32_t(changeNotification.IsClear()))) { + ZLOGE("write deviceId to parcel failed"); + return; + } + if (!data.WriteInt32(changeNotification.GetInsertEntries().size()) || + !data.WriteInt32(changeNotification.GetUpdateEntries().size()) || + !data.WriteInt32(changeNotification.GetDeleteEntries().size())) { + ZLOGE("write change size to parcel failed"); + return; + } + std::vector totalEntries; + totalEntries.insert(totalEntries.end(), changeNotification.GetInsertEntries().begin(), + changeNotification.GetInsertEntries().end()); + totalEntries.insert(totalEntries.end(), changeNotification.GetUpdateEntries().begin(), + changeNotification.GetUpdateEntries().end()); + totalEntries.insert(totalEntries.end(), changeNotification.GetDeleteEntries().begin(), + changeNotification.GetDeleteEntries().end()); + if (!ITypesUtil::MarshalToBuffer(totalEntries, totalSize, data)) { ZLOGE("WriteChangeList to Parcel by buffer failed"); return; }