Skip to content

Commit

Permalink
Avoid unsafe forms for base::File::WriteAtCurrentPos()
Browse files Browse the repository at this point in the history
Use the span based forms instead. Adjust callers to accomodate
an optional<size_t> return.

This CL was uploaded by git cl split.

R=kmackay@chromium.org

Bug: 42271176
Change-Id: Ie23c1540c6641d4e9ef03c37631bf913dbe31b52
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5818994
Auto-Submit: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Kenneth MacKay <kmackay@chromium.org>
Commit-Queue: Kenneth MacKay <kmackay@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1347712}
  • Loading branch information
tsepez authored and Chromium LUCI CQ committed Aug 27, 2024
1 parent 1a7687a commit 74223c9
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions chromecast/media/cma/backend/cplay/cplay.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <string>
#include <vector>

#include "base/containers/span.h"
#include "base/files/file.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
Expand Down Expand Up @@ -182,8 +183,7 @@ class WavOutputHandler : public OutputHandler {

// Write wav file header to fill space. We'll need to go back and fill in
// the size later.
wav_file_.WriteAtCurrentPos(reinterpret_cast<char*>(&header_),
sizeof(header_));
wav_file_.WriteAtCurrentPos(base::byte_span_from_ref(header_));
}

WavOutputHandler(const WavOutputHandler&) = delete;
Expand All @@ -208,8 +208,7 @@ class WavOutputHandler : public OutputHandler {
clipped_data[i] = std::clamp(clipped_data[i], -1.0f, 1.0f);
}
}
wav_file_.WriteAtCurrentPos(reinterpret_cast<char*>(clipped_data.data()),
sizeof(clipped_data[0]) * clipped_data.size());
wav_file_.WriteAtCurrentPos(base::as_byte_span(clipped_data));
}

private:
Expand Down

0 comments on commit 74223c9

Please sign in to comment.