Commit 88622215 authored by dcheng's avatar dcheng Committed by Commit bot

mojo: Mark DataView readers as WARN_UNUSED_RESULT.

It's important to check this return value to make sure that
deserialization actually succeeded.

BUG=652129

Review-Url: https://codereview.chromium.org/2392713002
Cr-Commit-Position: refs/heads/master@{#422681}
parent 234079c8
......@@ -34,6 +34,8 @@ namespace mojo {
std::vector<uint8_t>
StructTraits<arc::mojom::BluetoothUUIDDataView, device::BluetoothUUID>::uuid(
const device::BluetoothUUID& input) {
// TODO(dcheng): Figure out what to do here, this is called twice on
// serialization. Building a vector is a little inefficient.
std::string uuid_str = StripNonHex(input.canonical_value());
std::vector<uint8_t> address_bytes;
......@@ -47,7 +49,8 @@ bool StructTraits<arc::mojom::BluetoothUUIDDataView,
arc::mojom::BluetoothUUIDDataView data,
device::BluetoothUUID* output) {
std::vector<uint8_t> address_bytes;
data.ReadUuid(&address_bytes);
if (!data.ReadUuid(&address_bytes))
return false;
if (address_bytes.size() != kUUIDSize)
return false;
......
......@@ -42,6 +42,7 @@ namespace {{namespace}} {
#include <type_traits>
#include <utility>
#include "base/compiler_specific.h"
#include "mojo/public/cpp/bindings/array_data_view.h"
#include "mojo/public/cpp/bindings/enum_traits.h"
#include "mojo/public/cpp/bindings/interface_data_view.h"
......
......@@ -21,12 +21,12 @@ class {{struct.name}}DataView {
{{kind|cpp_data_view_type}}* output);
template <typename UserType>
bool Read{{name|under_to_camel}}(UserType* output) {
WARN_UNUSED_RESULT bool Read{{name|under_to_camel}}(UserType* output) {
{%- if pf.min_version != 0 %}
auto pointer = data_->header_.version >= {{pf.min_version}}
? &data_->{{name}} : nullptr;
auto* pointer = data_->header_.version >= {{pf.min_version}}
? &data_->{{name}} : nullptr;
{%- else %}
auto pointer = &data_->{{name}};
auto* pointer = &data_->{{name}};
{%- endif %}
return mojo::internal::Deserialize<{{kind|unmapped_type_for_serializer}}>(
pointer, output, context_);
......@@ -37,12 +37,12 @@ class {{struct.name}}DataView {
{{kind|cpp_data_view_type}}* output);
template <typename UserType>
bool Read{{name|under_to_camel}}(UserType* output) {
WARN_UNUSED_RESULT bool Read{{name|under_to_camel}}(UserType* output) {
{%- if pf.min_version != 0 %}
auto pointer = data_->header_.version >= {{pf.min_version}}
? data_->{{name}}.Get() : nullptr;
auto* pointer = data_->header_.version >= {{pf.min_version}}
? data_->{{name}}.Get() : nullptr;
{%- else %}
auto pointer = data_->{{name}}.Get();
auto* pointer = data_->{{name}}.Get();
{%- endif %}
return mojo::internal::Deserialize<{{kind|unmapped_type_for_serializer}}>(
pointer, output, context_);
......@@ -50,7 +50,7 @@ class {{struct.name}}DataView {
{%- elif kind|is_enum_kind %}
template <typename UserType>
bool Read{{name|under_to_camel}}(UserType* output) const {
WARN_UNUSED_RESULT bool Read{{name|under_to_camel}}(UserType* output) const {
{%- if pf.min_version != 0 %}
auto data_value = data_->header_.version >= {{pf.min_version}}
? data_->{{name}} : 0;
......
......@@ -31,7 +31,7 @@ class {{union.name}}DataView {
{{kind|cpp_data_view_type}}* output);
template <typename UserType>
bool Read{{name|under_to_camel}}(UserType* output) {
WARN_UNUSED_RESULT bool Read{{name|under_to_camel}}(UserType* output) {
DCHECK(is_{{name}}());
return mojo::internal::Deserialize<{{kind|unmapped_type_for_serializer}}>(
data_->data.f_{{name}}.Get(), output, context_);
......@@ -39,7 +39,7 @@ class {{union.name}}DataView {
{%- elif kind|is_enum_kind %}
template <typename UserType>
bool Read{{name|under_to_camel}}(UserType* output) const {
WARN_UNUSED_RESULT bool Read{{name|under_to_camel}}(UserType* output) const {
DCHECK(is_{{name}}());
return mojo::internal::Deserialize<{{kind|unmapped_type_for_serializer}}>(
data_->data.f_{{name}}, output);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment