mirror of
https://github.com/simonask/libyaml-safer
synced 2024-11-13 23:27:16 +00:00
Remove more c2rust artifacts (gotos)
This commit is contained in:
parent
edf4843cae
commit
9f681e6306
3 changed files with 98 additions and 156 deletions
|
@ -50,23 +50,14 @@ pub unsafe fn yaml_emitter_dump(
|
|||
emitter: &mut yaml_emitter_t,
|
||||
document: &mut yaml_document_t,
|
||||
) -> Result<(), ()> {
|
||||
let current_block: u64;
|
||||
if !emitter.opened {
|
||||
if yaml_emitter_open(emitter).is_err() {
|
||||
current_block = 5018439318894558507;
|
||||
} else {
|
||||
current_block = 15619007995458559411;
|
||||
}
|
||||
} else {
|
||||
current_block = 15619007995458559411;
|
||||
}
|
||||
match current_block {
|
||||
15619007995458559411 => {
|
||||
if document.nodes.is_empty() {
|
||||
if let Ok(()) = yaml_emitter_close(emitter) {
|
||||
if let Err(()) = yaml_emitter_open(emitter) {
|
||||
yaml_emitter_delete_document_and_anchors(emitter, document);
|
||||
return Ok(());
|
||||
return Err(());
|
||||
}
|
||||
}
|
||||
if document.nodes.is_empty() {
|
||||
yaml_emitter_close(emitter)?;
|
||||
} else {
|
||||
__assert!(emitter.opened);
|
||||
emitter.anchors = vec![yaml_anchors_t::default(); (*document).nodes.len()];
|
||||
|
@ -78,27 +69,20 @@ pub unsafe fn yaml_emitter_dump(
|
|||
},
|
||||
..Default::default()
|
||||
};
|
||||
if let Ok(()) = yaml_emitter_emit(emitter, event) {
|
||||
yaml_emitter_emit(emitter, event)?;
|
||||
yaml_emitter_anchor_node(emitter, document, 1);
|
||||
if let Ok(()) = yaml_emitter_dump_node(emitter, document, 1) {
|
||||
yaml_emitter_dump_node(emitter, document, 1)?;
|
||||
let event = yaml_event_t {
|
||||
data: YamlEventData::DocumentEnd {
|
||||
implicit: document.end_implicit,
|
||||
},
|
||||
..Default::default()
|
||||
};
|
||||
if let Ok(()) = yaml_emitter_emit(emitter, event) {
|
||||
yaml_emitter_emit(emitter, event)?;
|
||||
}
|
||||
|
||||
yaml_emitter_delete_document_and_anchors(emitter, document);
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
yaml_emitter_delete_document_and_anchors(emitter, document);
|
||||
Err(())
|
||||
Ok(())
|
||||
}
|
||||
|
||||
unsafe fn yaml_emitter_delete_document_and_anchors(
|
||||
|
|
|
@ -28,7 +28,6 @@ pub unsafe fn yaml_parser_load(
|
|||
parser: &mut yaml_parser_t,
|
||||
document: *mut yaml_document_t,
|
||||
) -> Result<(), ()> {
|
||||
let current_block: u64;
|
||||
let mut event = yaml_event_t::default();
|
||||
core::ptr::write(document, yaml_document_t::default());
|
||||
let document = &mut *document;
|
||||
|
@ -36,18 +35,17 @@ pub unsafe fn yaml_parser_load(
|
|||
|
||||
if !parser.stream_start_produced {
|
||||
if let Err(()) = yaml_parser_parse(parser, &mut event) {
|
||||
current_block = 6234624449317607669;
|
||||
yaml_parser_delete_aliases(parser);
|
||||
yaml_document_delete(document);
|
||||
parser.document = ptr::null_mut::<yaml_document_t>();
|
||||
return Err(());
|
||||
} else {
|
||||
if let YamlEventData::StreamStart { .. } = &event.data {
|
||||
} else {
|
||||
panic!("expected stream start");
|
||||
}
|
||||
current_block = 7815301370352969686;
|
||||
}
|
||||
} else {
|
||||
current_block = 7815301370352969686;
|
||||
}
|
||||
if current_block != 6234624449317607669 {
|
||||
if parser.stream_end_produced {
|
||||
return Ok(());
|
||||
}
|
||||
|
@ -63,7 +61,6 @@ pub unsafe fn yaml_parser_load(
|
|||
return Ok(());
|
||||
}
|
||||
}
|
||||
}
|
||||
yaml_parser_delete_aliases(parser);
|
||||
yaml_document_delete(document);
|
||||
parser.document = ptr::null_mut::<yaml_document_t>();
|
||||
|
@ -210,7 +207,6 @@ unsafe fn yaml_parser_load_node_add(
|
|||
}
|
||||
let parent_index: libc::c_int = *ctx.last().unwrap();
|
||||
let parent = &mut (*parser.document).nodes[parent_index as usize - 1];
|
||||
let current_block_17: u64;
|
||||
match parent.data {
|
||||
YamlNodeData::Sequence { ref mut items, .. } => {
|
||||
STACK_LIMIT!(parser, items)?;
|
||||
|
@ -219,27 +215,21 @@ unsafe fn yaml_parser_load_node_add(
|
|||
YamlNodeData::Mapping { ref mut pairs, .. } => {
|
||||
let mut pair = MaybeUninit::<yaml_node_pair_t>::uninit();
|
||||
let pair = pair.as_mut_ptr();
|
||||
let mut do_push = true;
|
||||
if !pairs.is_empty() {
|
||||
let p: &mut yaml_node_pair_t = pairs.last_mut().unwrap();
|
||||
if p.key != 0 && p.value == 0 {
|
||||
p.value = index;
|
||||
current_block_17 = 11307063007268554308;
|
||||
} else {
|
||||
current_block_17 = 17407779659766490442;
|
||||
do_push = false;
|
||||
}
|
||||
} else {
|
||||
current_block_17 = 17407779659766490442;
|
||||
}
|
||||
match current_block_17 {
|
||||
11307063007268554308 => {}
|
||||
_ => {
|
||||
if do_push {
|
||||
(*pair).key = index;
|
||||
(*pair).value = 0;
|
||||
STACK_LIMIT!(parser, pairs)?;
|
||||
pairs.push(*pair);
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
__assert!(false);
|
||||
}
|
||||
|
|
|
@ -838,7 +838,6 @@ unsafe fn yaml_parser_scan_directive(
|
|||
parser: &mut yaml_parser_t,
|
||||
token: &mut yaml_token_t,
|
||||
) -> Result<(), ()> {
|
||||
let mut current_block: u64;
|
||||
let end_mark: yaml_mark_t;
|
||||
let mut major: libc::c_int = 0;
|
||||
let mut minor: libc::c_int = 0;
|
||||
|
@ -846,31 +845,22 @@ unsafe fn yaml_parser_scan_directive(
|
|||
SKIP(parser);
|
||||
if let Ok(name) = yaml_parser_scan_directive_name(parser, start_mark) {
|
||||
if name == "YAML" {
|
||||
if let Err(()) =
|
||||
yaml_parser_scan_version_directive_value(parser, start_mark, &mut major, &mut minor)
|
||||
{
|
||||
current_block = 11397968426844348457;
|
||||
} else {
|
||||
yaml_parser_scan_version_directive_value(parser, start_mark, &mut major, &mut minor)?;
|
||||
|
||||
end_mark = parser.mark;
|
||||
*token = yaml_token_t {
|
||||
data: YamlTokenData::VersionDirective { major, minor },
|
||||
start_mark,
|
||||
end_mark,
|
||||
};
|
||||
current_block = 17407779659766490442;
|
||||
}
|
||||
} else if name == "TAG" {
|
||||
if let Ok((handle, prefix)) = yaml_parser_scan_tag_directive_value(parser, start_mark) {
|
||||
let (handle, prefix) = yaml_parser_scan_tag_directive_value(parser, start_mark)?;
|
||||
end_mark = parser.mark;
|
||||
*token = yaml_token_t {
|
||||
data: YamlTokenData::TagDirective { handle, prefix },
|
||||
start_mark,
|
||||
end_mark,
|
||||
};
|
||||
current_block = 17407779659766490442;
|
||||
} else {
|
||||
current_block = 11397968426844348457;
|
||||
}
|
||||
} else {
|
||||
yaml_parser_set_scanner_error(
|
||||
parser,
|
||||
|
@ -878,38 +868,27 @@ unsafe fn yaml_parser_scan_directive(
|
|||
start_mark,
|
||||
"found unknown directive name",
|
||||
);
|
||||
current_block = 11397968426844348457;
|
||||
return Err(());
|
||||
}
|
||||
if current_block != 11397968426844348457 {
|
||||
if let Ok(()) = CACHE(parser, 1_u64) {
|
||||
CACHE(parser, 1_u64)?;
|
||||
loop {
|
||||
if !IS_BLANK!(parser.buffer) {
|
||||
current_block = 11584701595673473500;
|
||||
break;
|
||||
}
|
||||
SKIP(parser);
|
||||
if let Err(()) = CACHE(parser, 1_u64) {
|
||||
current_block = 11397968426844348457;
|
||||
break;
|
||||
CACHE(parser, 1_u64)?;
|
||||
}
|
||||
}
|
||||
if current_block != 11397968426844348457 {
|
||||
|
||||
if CHECK!(parser.buffer, b'#') {
|
||||
loop {
|
||||
if IS_BREAKZ!(parser.buffer) {
|
||||
current_block = 6669252993407410313;
|
||||
break;
|
||||
}
|
||||
SKIP(parser);
|
||||
if let Err(()) = CACHE(parser, 1_u64) {
|
||||
current_block = 11397968426844348457;
|
||||
break;
|
||||
CACHE(parser, 1_u64)?;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
current_block = 6669252993407410313;
|
||||
}
|
||||
if current_block != 11397968426844348457 {
|
||||
|
||||
if !IS_BREAKZ!(parser.buffer) {
|
||||
yaml_parser_set_scanner_error(
|
||||
parser,
|
||||
|
@ -917,26 +896,15 @@ unsafe fn yaml_parser_scan_directive(
|
|||
start_mark,
|
||||
"did not find expected comment or line break",
|
||||
);
|
||||
return Err(());
|
||||
} else {
|
||||
if IS_BREAK!(parser.buffer) {
|
||||
if let Err(()) = CACHE(parser, 2_u64) {
|
||||
current_block = 11397968426844348457;
|
||||
} else {
|
||||
CACHE(parser, 2_u64)?;
|
||||
SKIP_LINE(parser);
|
||||
current_block = 652864300344834934;
|
||||
}
|
||||
} else {
|
||||
current_block = 652864300344834934;
|
||||
}
|
||||
if current_block != 11397968426844348457 {
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(())
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue