Avoid unsafe forms for base::File::WriteAtCurrentPos()
Use the span based forms instead. Adjust callers to accommodate
an optional<size_t> return.
This CL was uploaded by git cl split.
R=lizeb@chromium.org, olivierli@chromium.org, pasko@chromium.org
Bug: 42271176
Change-Id: Ia97077b38293bd6713b5afa69641c771b74db260
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5819672
Reviewed-by: Benoit Lize <lizeb@chromium.org>
Reviewed-by: Egor Pasko <pasko@chromium.org>
Auto-Submit: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Olivier Li <olivierli@chromium.org>
Reviewed-by: Olivier Li <olivierli@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1356595}
NOKEYCHECK=True
GitOrigin-RevId: 5294874506edca885248dc8097ab0678a39461fe
diff --git a/partition_allocator/pa_buckets_inspect.cc b/partition_allocator/pa_buckets_inspect.cc
index 566da97..396489f 100644
--- a/partition_allocator/pa_buckets_inspect.cc
+++ b/partition_allocator/pa_buckets_inspect.cc
@@ -100,8 +100,7 @@
std::string written = base::StringPrintf(
"%zu,%lu,%zu,%zu,%zu,%zu\n", i, bucket_size, alloc_nums[i],
alloc_size[i], alt_alloc_nums[i], alt_alloc_size[i]);
- if (f.WriteAtCurrentPos(written.data(), written.size()) !=
- static_cast<int>(written.size())) {
+ if (!f.WriteAtCurrentPosAndCheck(base::as_byte_span(written))) {
std::cerr << "WARNING: Unable to write to temp file, data will be "
"stale/missing.\n";
return;
diff --git a/partition_allocator/pa_dump_heap.cc b/partition_allocator/pa_dump_heap.cc
index 90b3ee5..0d45993 100644
--- a/partition_allocator/pa_dump_heap.cc
+++ b/partition_allocator/pa_dump_heap.cc
@@ -16,6 +16,7 @@
#include "base/bits.h"
#include "base/check.h"
#include "base/command_line.h"
+#include "base/containers/span.h"
#include "base/files/file.h"
#include "base/json/json_writer.h"
#include "base/logging.h"
@@ -476,7 +477,7 @@
auto f = base::File(json_filename, base::File::Flags::FLAG_CREATE_ALWAYS |
base::File::Flags::FLAG_WRITE);
if (f.IsValid()) {
- f.WriteAtCurrentPos(json_string.c_str(), json_string.size());
+ f.WriteAtCurrentPos(base::as_byte_span(json_string));
LOG(WARNING) << "\n\nDumped JSON to " << json_filename;
return 0;
}
diff --git a/partition_allocator/pa_tcache_inspect.cc b/partition_allocator/pa_tcache_inspect.cc
index 3f43f00..026e324 100644
--- a/partition_allocator/pa_tcache_inspect.cc
+++ b/partition_allocator/pa_tcache_inspect.cc
@@ -23,6 +23,7 @@
#include "base/check_op.h"
#include "base/command_line.h"
+#include "base/containers/span.h"
#include "base/debug/proc_maps_linux.h"
#include "base/files/file.h"
#include "base/files/file_enumerator.h"
@@ -630,7 +631,7 @@
base::File(json_filename, base::File::Flags::FLAG_OPEN_ALWAYS |
base::File::Flags::FLAG_WRITE);
if (f.IsValid()) {
- f.WriteAtCurrentPos(json_string.c_str(), json_string.size());
+ f.WriteAtCurrentPos(base::as_byte_span(json_string));
std::cout << "\n\nDumped JSON to " << json_filename << std::endl;
return 0;
}