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

Side by Side Diff: mojo/public/rust/tests/util/mod.rs

Issue 2220183003: Rust: Add validation to decode (Closed) Base URL: git@github.com:domokit/mojo.git@coder-testing
Patch Set: Update from upstream branches (fixed arrays, validation code, etc.) Created 4 years, 4 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
« no previous file with comments | « mojo/public/rust/tests/regression.rs ('k') | mojo/public/rust/tests/util/mojom_validation.rs » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 //! This module contains useful functions and macros for testing. 5 //! This module contains useful functions and macros for testing.
6 6
7 pub mod mojom_validation; 7 pub mod mojom_validation;
8 8
9 use std::ffi::{CStr, CString}; 9 use std::ffi::{CStr, CString};
10 use std::os::raw::c_char; 10 use std::os::raw::c_char;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 let mut num_handles: usize = 0; 61 let mut num_handles: usize = 0;
62 let mut data: *mut u8 = ptr::null_mut(); 62 let mut data: *mut u8 = ptr::null_mut();
63 let mut data_len: usize = 0; 63 let mut data_len: usize = 0;
64 let error = unsafe { 64 let error = unsafe {
65 ParseValidationTest(input_c.as_ptr(), 65 ParseValidationTest(input_c.as_ptr(),
66 &mut num_handles as *mut usize, 66 &mut num_handles as *mut usize,
67 &mut data as *mut *mut u8, 67 &mut data as *mut *mut u8,
68 &mut data_len as *mut usize) 68 &mut data_len as *mut usize)
69 }; 69 };
70 if error == ptr::null_mut() { 70 if error == ptr::null_mut() {
71 if data == ptr::null_mut() { 71 if data == ptr::null_mut() || data_len == 0 {
72 // We assume we were just given an empty file 72 // We assume we were just given an empty file
73 Ok((Vec::new(), 0)) 73 Ok((Vec::new(), 0))
74 } else { 74 } else {
75 // Make a copy of the buffer 75 // Make a copy of the buffer
76 let buffer; 76 let buffer;
77 unsafe { 77 unsafe {
78 buffer = slice::from_raw_parts(data, data_len).to_vec(); 78 buffer = slice::from_raw_parts(data, data_len).to_vec();
79 free(data); 79 free(data);
80 } 80 }
81 Ok((buffer, num_handles)) 81 Ok((buffer, num_handles))
82 } 82 }
83 } else { 83 } else {
84 let err_str; 84 let err_str;
85 unsafe { 85 unsafe {
86 // Copy the error string 86 // Copy the error string
87 err_str = CStr::from_ptr(error) 87 err_str = CStr::from_ptr(error)
88 .to_str() 88 .to_str()
89 .expect("Could not convert error message to UTF-8!") 89 .expect("Could not convert error message to UTF-8!")
90 .to_owned(); 90 .to_owned();
91 free(error as *mut u8); 91 free(error as *mut u8);
92 } 92 }
93 Err(err_str) 93 Err(err_str)
94 } 94 }
95 } 95 }
OLDNEW
« no previous file with comments | « mojo/public/rust/tests/regression.rs ('k') | mojo/public/rust/tests/util/mojom_validation.rs » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698