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

Side by Side Diff: mojo/public/c/bindings/lib/struct.c

Issue 1654373002: C types and utilities to validate and access struct and message headers (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 4 years, 10 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "mojo/public/c/bindings/struct.h"
6
7 _Static_assert(sizeof(mojo_struct_header_t) == 8u,
8 "mojo_struct_header_t should be 8 bytes");
9
10 bool mojo_validate_struct_header(void* data, uint32_t size) {
11 if (size < sizeof(mojo_struct_header_t)) {
12 return false;
13 }
14
15 mojo_struct_header_t* header = (mojo_struct_header_t*)data;
16
17 if (header->num_bytes < sizeof(mojo_struct_header_t) ||
18 header->num_bytes > size) {
19 return false;
20 }
21
22 return true;
23 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698