<commit_before>#![no_main]
extern crate libfuzzer_sys;
extern crate capnp;

use capnp::{serialize, message};
use test_capnp::test_all_types;

pub mod test_capnp;

fn traverse(v: test_all_types::Reader) -> ::capnp::Result<()> {
    v.get_int64_field();
    try!(v.get_text_field());
    try!(v.get_data_field());
    try!(v.get_struct_field());

    let structs = try!(v.get_struct_list());
    for s in structs.iter() {
        try!(s.get_text_field());
    }

    try!(v.get_bool_list());
    Ok(())
}

fn try_go(mut data: &[u8]) -> ::capnp::Result<()> {
    let orig_data = data;
    let message_reader = try!(serialize::read_message(
        &mut data,
        *message::ReaderOptions::new().traversal_limit_in_words(4 * 1024)));
    assert!(orig_data.len() > data.len());

    let root: test_all_types::Reader = try!(message_reader.get_root());
    try!(root.total_size());
    try!(traverse(root));

    let mut message = message::Builder::new_default();
    try!(message.set_root(root));
    {
        let root_builder = try!(message.get_root::<test_all_types::Builder>());
        try!(root_builder.total_size());
        try!(traverse(root_builder.as_reader()));
    }

    // init_root() will zero the previous value
    let mut new_root = message.init_root::<test_all_types::Builder>();

    try!(new_root.set_struct_field(root));
    Ok(())
}

#[export_name="rust_fuzzer_test_input"]
pub extern fn go(data: &[u8]) {
    let _ = try_go(data);
}<commit_msg>add a bit more traversal in the test_all_types fuzzer<commit_after>#![no_main]
extern crate libfuzzer_sys;
extern crate capnp;

use capnp::{serialize, message};
use test_capnp::test_all_types;

pub mod test_capnp;

fn traverse(v: test_all_types::Reader) -> ::capnp::Result<()> {
    v.get_int64_field();
    v.get_float32_field();
    v.get_float64_field();
    v.get_text_field()?;
    v.get_data_field()?;
    v.get_struct_field()?;
    v.get_enum_field()?;

    let structs = v.get_struct_list()?;
    for s in structs.iter() {
        s.get_text_field()?;
        s.get_data_field()?;
    }

    let bools = v.get_bool_list()?;
    for idx in 0 .. bools.len() {
        bools.get(idx);
    }

    let enums = v.get_enum_list()?;
    for idx in 0 .. enums.len() {
        enums.get(idx)?;
    }

    let int8s = v.get_int8_list()?;
    for idx in 0 .. int8s.len() {
        int8s.get(idx);
    }

    Ok(())
}

fn try_go(mut data: &[u8]) -> ::capnp::Result<()> {
    let orig_data = data;
    let message_reader = serialize::read_message(
        &mut data,
        *message::ReaderOptions::new().traversal_limit_in_words(4 * 1024))?;
    assert!(orig_data.len() > data.len());

    let root: test_all_types::Reader = try!(message_reader.get_root());
    root.total_size()?;
    traverse(root)?;

    let mut message = message::Builder::new_default();
    message.set_root(root)?;
    {
        let root_builder = message.get_root::<test_all_types::Builder>()?;
        root_builder.total_size()?;
        traverse(root_builder.as_reader())?;
    }

    // init_root() will zero the previous value
    let mut new_root = message.init_root::<test_all_types::Builder>();

    new_root.set_struct_field(root)?;
    Ok(())
}

#[export_name="rust_fuzzer_test_input"]
pub extern fn go(data: &[u8]) {
    let _ = try_go(data);
}
{'fraction_non_alphanumeric': 0.16930091185410334, 'fraction_numerical': 0.008814589665653495, 'mean_word_length': 3.5581717451523547, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6942706', 'n_tokens_mistral': 1222, 'n_tokens_neox': 1208, 'n_words': 210}