Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(860)

Unified Diff: mojo/public/cpp/bindings/lib/array_serialization.h

Issue 659313006: mojo: Fix c++ bindings so serialization of empty arrays doesn't crash. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git/+/master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | mojo/public/cpp/bindings/tests/array_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/cpp/bindings/lib/array_serialization.h
diff --git a/mojo/public/cpp/bindings/lib/array_serialization.h b/mojo/public/cpp/bindings/lib/array_serialization.h
index e73553d89b39a6f2ba4142cd6e83ffec769a3acb..eacf298ec80ea46fffebe0afa499a32f83325316 100644
--- a/mojo/public/cpp/bindings/lib/array_serialization.h
+++ b/mojo/public/cpp/bindings/lib/array_serialization.h
@@ -63,11 +63,13 @@ struct ArraySerializer<E, F, false> {
static_assert((IsSame<ElementValidateParams, NoValidateParams>::value),
"Primitive type should not have array validate params");
- memcpy(output->storage(), &input.storage()[0], input.size() * sizeof(E));
+ if (input.size())
+ memcpy(output->storage(), &input.storage()[0], input.size() * sizeof(E));
}
static void DeserializeElements(Array_Data<F>* input, Array<E>* output) {
std::vector<E> result(input->size());
- memcpy(&result[0], input->storage(), input->size() * sizeof(E));
+ if (input->size())
+ memcpy(&result[0], input->storage(), input->size() * sizeof(E));
output->Swap(&result);
}
};
« no previous file with comments | « no previous file | mojo/public/cpp/bindings/tests/array_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698