Skip to content

Commit

Permalink
Fix platform service DCHECK on null data
Browse files Browse the repository at this point in the history
The starboard implementation of platform service Send() may not
handle null for the data pointer. If we're sending 0-length data,
then it should be okay to make data point to a dummy array.

b/198487871

Change-Id: I8f44850ea95dcdd61521a47e7206c1c8ee9cae97
(cherry picked from commit c4103236b4c624bb5a7a051103abf464d36d9b89)
  • Loading branch information
tphamg committed Sep 2, 2021
1 parent 6b42479 commit d9b2e75
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions cobalt/h5vcc/h5vcc_platform_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,21 @@ script::Handle<script::ArrayBuffer> H5vccPlatformService::Send(
}
uint64_t output_length = 0;
bool invalid_state = 0;

// Make sure the data pointer is not null as the platform service may not
// handle that properly.
void* data_ptr = data->Data();
size_t data_length = data->ByteLength();
if (data_ptr == nullptr) {
// If the data length is 0, then it's okay to point to a static array.
DCHECK(data_length == 0);
static int null_data = 0;
data_ptr = &null_data;
data_length = 0;
}

void* output_data = platform_service_api_->Send(
ext_service_, data->Data(), data->ByteLength(), &output_length,
&invalid_state);
ext_service_, data_ptr, data_length, &output_length, &invalid_state);
if (invalid_state) {
dom::DOMException::Raise(dom::DOMException::kInvalidStateErr,
"Service unable to accept data currently.",
Expand Down

0 comments on commit d9b2e75

Please sign in to comment.