diff options
author | 2022-08-30 14:27:35 -0700 | |
---|---|---|
committer | 2022-09-01 13:28:54 -0700 | |
commit | 8ebb1dd9722aa51c557799c3d368c63d4ceaf488 (patch) | |
tree | fdedc0b3accd38a38f326838d3761532fb909ea8 | |
parent | 565f2ab1156bfe8b90bfd6904722109002380645 (diff) |
incfs: tolerate either ptrdiff_t or size_t for std::span
The out-of-date std::span in external/libcxx currently uses ptrdiff_t
as the type of size() and the second ctor argument. The C++20 std::span
actually uses size_t for these values instead. Try to accommodate both
versions of std::span until libc++ is upgraded.
Bug: http://b/175635923
Test: treehugger
Change-Id: Idc43f880b6eb21dad79e79fa456847d5865a1ed2
-rw-r--r-- | services/incremental/BinderIncrementalService.cpp | 5 | ||||
-rw-r--r-- | services/incremental/IncrementalService.cpp | 6 |
2 files changed, 7 insertions, 4 deletions
diff --git a/services/incremental/BinderIncrementalService.cpp b/services/incremental/BinderIncrementalService.cpp index 2f031bfe4f3f..45ca5cd84e39 100644 --- a/services/incremental/BinderIncrementalService.cpp +++ b/services/incremental/BinderIncrementalService.cpp @@ -216,7 +216,10 @@ static std::span<const uint8_t> toSpan(const ::std::optional<::std::vector<uint8 if (!content) { return {}; } - return {content->data(), (int)content->size()}; + // TODO(b/175635923): Replace with {content->data(), content->size()} after libc++ is upgraded. + // The type of the second std::span ctor param changed from ptrdiff_t to size_t between the old + // libc++ and the finalized C++20. + return std::span<const uint8_t>(content->data(), content->size()); } binder::Status BinderIncrementalService::makeFile( diff --git a/services/incremental/IncrementalService.cpp b/services/incremental/IncrementalService.cpp index a49577b21957..6196c49c88ce 100644 --- a/services/incremental/IncrementalService.cpp +++ b/services/incremental/IncrementalService.cpp @@ -1166,11 +1166,11 @@ int IncrementalService::makeFile(StorageId storage, std::string_view path, int m if (!ifs) { return -EINVAL; } - if (data.size() > params.size) { + if ((IncFsSize)data.size() > params.size) { LOG(ERROR) << "Bad data size - bigger than file size"; return -EINVAL; } - if (!data.empty() && data.size() != params.size) { + if (!data.empty() && (IncFsSize)data.size() != params.size) { // Writing a page is an irreversible operation, and it can't be updated with additional // data later. Check that the last written page is complete, or we may break the file. if (!isPageAligned(data.size())) { @@ -3188,7 +3188,7 @@ binder::Status IncrementalService::IncrementalServiceConnector::setStorageParams } FileId IncrementalService::idFromMetadata(std::span<const uint8_t> metadata) { - return IncFs_FileIdFromMetadata({(const char*)metadata.data(), metadata.size()}); + return IncFs_FileIdFromMetadata({(const char*)metadata.data(), (IncFsSize)metadata.size()}); } } // namespace android::incremental |