Lint; Remove Result from infallible functions

This commit is contained in:
Simon Ask Ulsnes 2024-02-02 10:38:33 +01:00
parent cac3d2d788
commit 8a080a1ce7
6 changed files with 113 additions and 178 deletions

View file

@ -204,24 +204,19 @@ pub fn yaml_token_delete(token: &mut yaml_token_t) {
} }
/// Create the STREAM-START event. /// Create the STREAM-START event.
pub fn yaml_stream_start_event_initialize( pub fn yaml_stream_start_event_initialize(event: &mut yaml_event_t, encoding: yaml_encoding_t) {
event: &mut yaml_event_t,
encoding: yaml_encoding_t,
) -> Result<(), ()> {
*event = yaml_event_t { *event = yaml_event_t {
data: YamlEventData::StreamStart { encoding }, data: YamlEventData::StreamStart { encoding },
..Default::default() ..Default::default()
}; };
Ok(())
} }
/// Create the STREAM-END event. /// Create the STREAM-END event.
pub fn yaml_stream_end_event_initialize(event: &mut yaml_event_t) -> Result<(), ()> { pub fn yaml_stream_end_event_initialize(event: &mut yaml_event_t) {
*event = yaml_event_t { *event = yaml_event_t {
data: YamlEventData::StreamEnd, data: YamlEventData::StreamEnd,
..Default::default() ..Default::default()
}; };
Ok(())
} }
/// Create the DOCUMENT-START event. /// Create the DOCUMENT-START event.
@ -233,7 +228,7 @@ pub fn yaml_document_start_event_initialize(
version_directive: Option<yaml_version_directive_t>, version_directive: Option<yaml_version_directive_t>,
tag_directives_in: &[yaml_tag_directive_t], tag_directives_in: &[yaml_tag_directive_t],
implicit: bool, implicit: bool,
) -> Result<(), ()> { ) {
let tag_directives = Vec::from_iter(tag_directives_in.iter().cloned()); let tag_directives = Vec::from_iter(tag_directives_in.iter().cloned());
*event = yaml_event_t { *event = yaml_event_t {
@ -244,34 +239,27 @@ pub fn yaml_document_start_event_initialize(
}, },
..Default::default() ..Default::default()
}; };
Ok(())
} }
/// Create the DOCUMENT-END event. /// Create the DOCUMENT-END event.
/// ///
/// The `implicit` argument is considered as a stylistic parameter and may be /// The `implicit` argument is considered as a stylistic parameter and may be
/// ignored by the emitter. /// ignored by the emitter.
pub fn yaml_document_end_event_initialize( pub fn yaml_document_end_event_initialize(event: &mut yaml_event_t, implicit: bool) {
event: &mut yaml_event_t,
implicit: bool,
) -> Result<(), ()> {
*event = yaml_event_t { *event = yaml_event_t {
data: YamlEventData::DocumentEnd { implicit }, data: YamlEventData::DocumentEnd { implicit },
..Default::default() ..Default::default()
}; };
Ok(())
} }
/// Create an ALIAS event. /// Create an ALIAS event.
pub fn yaml_alias_event_initialize(event: &mut yaml_event_t, anchor: &str) -> Result<(), ()> { pub fn yaml_alias_event_initialize(event: &mut yaml_event_t, anchor: &str) {
*event = yaml_event_t { *event = yaml_event_t {
data: YamlEventData::Alias { data: YamlEventData::Alias {
anchor: String::from(anchor), anchor: String::from(anchor),
}, },
..Default::default() ..Default::default()
}; };
Ok(())
} }
/// Create a SCALAR event. /// Create a SCALAR event.
@ -289,7 +277,7 @@ pub fn yaml_scalar_event_initialize(
plain_implicit: bool, plain_implicit: bool,
quoted_implicit: bool, quoted_implicit: bool,
style: yaml_scalar_style_t, style: yaml_scalar_style_t,
) -> Result<(), ()> { ) {
let mark = yaml_mark_t { let mark = yaml_mark_t {
index: 0_u64, index: 0_u64,
line: 0_u64, line: 0_u64,
@ -317,7 +305,6 @@ pub fn yaml_scalar_event_initialize(
start_mark: mark, start_mark: mark,
end_mark: mark, end_mark: mark,
}; };
Ok(())
} }
/// Create a SEQUENCE-START event. /// Create a SEQUENCE-START event.
@ -331,7 +318,7 @@ pub fn yaml_sequence_start_event_initialize(
tag: Option<&str>, tag: Option<&str>,
implicit: bool, implicit: bool,
style: yaml_sequence_style_t, style: yaml_sequence_style_t,
) -> Result<(), ()> { ) {
let mut anchor_copy: Option<String> = None; let mut anchor_copy: Option<String> = None;
let mut tag_copy: Option<String> = None; let mut tag_copy: Option<String> = None;
@ -351,16 +338,14 @@ pub fn yaml_sequence_start_event_initialize(
}, },
..Default::default() ..Default::default()
}; };
Ok(())
} }
/// Create a SEQUENCE-END event. /// Create a SEQUENCE-END event.
pub fn yaml_sequence_end_event_initialize(event: &mut yaml_event_t) -> Result<(), ()> { pub fn yaml_sequence_end_event_initialize(event: &mut yaml_event_t) {
*event = yaml_event_t { *event = yaml_event_t {
data: YamlEventData::SequenceEnd, data: YamlEventData::SequenceEnd,
..Default::default() ..Default::default()
}; };
Ok(())
} }
/// Create a MAPPING-START event. /// Create a MAPPING-START event.
@ -374,7 +359,7 @@ pub fn yaml_mapping_start_event_initialize(
tag: Option<&str>, tag: Option<&str>,
implicit: bool, implicit: bool,
style: yaml_mapping_style_t, style: yaml_mapping_style_t,
) -> Result<(), ()> { ) {
let mut anchor_copy: Option<String> = None; let mut anchor_copy: Option<String> = None;
let mut tag_copy: Option<String> = None; let mut tag_copy: Option<String> = None;
@ -395,17 +380,14 @@ pub fn yaml_mapping_start_event_initialize(
}, },
..Default::default() ..Default::default()
}; };
Ok(())
} }
/// Create a MAPPING-END event. /// Create a MAPPING-END event.
pub fn yaml_mapping_end_event_initialize(event: &mut yaml_event_t) -> Result<(), ()> { pub fn yaml_mapping_end_event_initialize(event: &mut yaml_event_t) {
*event = yaml_event_t { *event = yaml_event_t {
data: YamlEventData::MappingEnd, data: YamlEventData::MappingEnd,
..Default::default() ..Default::default()
}; };
Ok(())
} }
/// Free any memory allocated for an event object. /// Free any memory allocated for an event object.
@ -420,7 +402,7 @@ pub fn yaml_document_initialize(
tag_directives_in: &[yaml_tag_directive_t], tag_directives_in: &[yaml_tag_directive_t],
start_implicit: bool, start_implicit: bool,
end_implicit: bool, end_implicit: bool,
) -> Result<(), ()> { ) {
let nodes = Vec::with_capacity(16); let nodes = Vec::with_capacity(16);
let tag_directives = Vec::from_iter(tag_directives_in.iter().cloned()); let tag_directives = Vec::from_iter(tag_directives_in.iter().cloned());
@ -432,8 +414,6 @@ pub fn yaml_document_initialize(
end_implicit, end_implicit,
..Default::default() ..Default::default()
}; };
Ok(())
} }
/// Delete a YAML document and all its nodes. /// Delete a YAML document and all its nodes.
@ -576,7 +556,7 @@ pub fn yaml_document_append_sequence_item(
document: &mut yaml_document_t, document: &mut yaml_document_t,
sequence: libc::c_int, sequence: libc::c_int,
item: libc::c_int, item: libc::c_int,
) -> Result<(), ()> { ) {
__assert!(sequence > 0 && sequence as usize - 1 < document.nodes.len()); __assert!(sequence > 0 && sequence as usize - 1 < document.nodes.len());
__assert!(matches!( __assert!(matches!(
&document.nodes[sequence as usize - 1].data, &document.nodes[sequence as usize - 1].data,
@ -588,7 +568,6 @@ pub fn yaml_document_append_sequence_item(
{ {
items.push(item); items.push(item);
} }
Ok(())
} }
/// Add a pair of a key and a value to a MAPPING node. /// Add a pair of a key and a value to a MAPPING node.
@ -597,7 +576,7 @@ pub fn yaml_document_append_mapping_pair(
mapping: libc::c_int, mapping: libc::c_int,
key: libc::c_int, key: libc::c_int,
value: libc::c_int, value: libc::c_int,
) -> Result<(), ()> { ) {
__assert!(mapping > 0 && mapping as usize - 1 < document.nodes.len()); __assert!(mapping > 0 && mapping as usize - 1 < document.nodes.len());
__assert!(matches!( __assert!(matches!(
&document.nodes[mapping as usize - 1].data, &document.nodes[mapping as usize - 1].data,
@ -611,5 +590,4 @@ pub fn yaml_document_append_mapping_pair(
{ {
pairs.push(pair); pairs.push(pair);
} }
Ok(())
} }

View file

@ -56,7 +56,7 @@ pub(crate) fn test_main(
} }
let line = line_buffer.strip_suffix('\n').unwrap_or(&line_buffer); let line = line_buffer.strip_suffix('\n').unwrap_or(&line_buffer);
let result = if line.starts_with("+STR") { if line.starts_with("+STR") {
yaml_stream_start_event_initialize(&mut event, YAML_UTF8_ENCODING) yaml_stream_start_event_initialize(&mut event, YAML_UTF8_ENCODING)
} else if line.starts_with("-STR") { } else if line.starts_with("-STR") {
yaml_stream_end_event_initialize(&mut event) yaml_stream_end_event_initialize(&mut event)
@ -105,9 +105,6 @@ pub(crate) fn test_main(
break Err(format!("Unknown event: '{line}'").into()); break Err(format!("Unknown event: '{line}'").into());
}; };
if result.is_err() {
break Err("Memory error: Not enough memory for creating an event".into());
}
if let Err(err) = yaml_emitter_emit(&mut emitter, event) { if let Err(err) = yaml_emitter_emit(&mut emitter, event) {
break Err(err.into()); break Err(err.into());
} }

View file

@ -2,7 +2,7 @@ use alloc::string::String;
use crate::api::OUTPUT_BUFFER_SIZE; use crate::api::OUTPUT_BUFFER_SIZE;
use crate::macros::{ use crate::macros::{
is_alpha, is_ascii, is_blank, is_blankz, is_bom, is_break, is_printable, is_space, is_alpha, is_ascii, is_blank, is_blankz, is_bom, is_break, is_breakz, is_printable, is_space,
}; };
use crate::ops::ForceMul as _; use crate::ops::ForceMul as _;
use crate::yaml::YamlEventData; use crate::yaml::YamlEventData;
@ -338,7 +338,7 @@ fn yaml_emitter_emit_document_start(
]; ];
let mut implicit = implicit; let mut implicit = implicit;
if let Some(version_directive) = version_directive { if let Some(version_directive) = version_directive {
yaml_emitter_analyze_version_directive(emitter, &version_directive)?; yaml_emitter_analyze_version_directive(emitter, version_directive)?;
} }
for tag_directive in tag_directives { for tag_directive in tag_directives {
yaml_emitter_analyze_tag_directive(emitter, tag_directive)?; yaml_emitter_analyze_tag_directive(emitter, tag_directive)?;
@ -477,7 +477,10 @@ fn yaml_emitter_emit_flow_mapping_key(
emitter.flow_level += 1; emitter.flow_level += 1;
} }
if let YamlEventData::MappingEnd = &event.data { if let YamlEventData::MappingEnd = &event.data {
assert!(!emitter.indents.is_empty(), "emitter.indents should not be empty"); assert!(
!emitter.indents.is_empty(),
"emitter.indents should not be empty"
);
emitter.flow_level -= 1; emitter.flow_level -= 1;
emitter.indent = emitter.indents.pop().unwrap(); emitter.indent = emitter.indents.pop().unwrap();
if emitter.canonical && !first { if emitter.canonical && !first {
@ -720,16 +723,8 @@ fn yaml_emitter_check_empty_sequence(emitter: &yaml_emitter_t, event: &yaml_even
if emitter.events.is_empty() { if emitter.events.is_empty() {
return false; return false;
} }
let start = if let YamlEventData::SequenceStart { .. } = event.data { let start = matches!(event.data, YamlEventData::SequenceStart { .. });
true let end = matches!(emitter.events[0].data, YamlEventData::SequenceEnd);
} else {
false
};
let end = if let YamlEventData::SequenceEnd = emitter.events[0].data {
true
} else {
false
};
start && end start && end
} }
@ -737,16 +732,8 @@ fn yaml_emitter_check_empty_mapping(emitter: &yaml_emitter_t, event: &yaml_event
if emitter.events.is_empty() { if emitter.events.is_empty() {
return false; return false;
} }
let start = if let YamlEventData::MappingStart { .. } = event.data { let start = matches!(event.data, YamlEventData::MappingStart { .. });
true let end = matches!(emitter.events[0].data, YamlEventData::MappingEnd);
} else {
false
};
let end = if let YamlEventData::MappingEnd = emitter.events[0].data {
true
} else {
false
};
start && end start && end
} }
@ -762,16 +749,11 @@ fn yaml_emitter_check_simple_key(
} = analysis; } = analysis;
let mut length = anchor.as_ref().map_or(0, |a| a.anchor.len()) let mut length = anchor.as_ref().map_or(0, |a| a.anchor.len())
+ tag + tag.as_ref().map_or(0, |t| t.handle.len() + t.suffix.len());
.as_ref()
.map_or(0, |t| t.handle.len() + t.suffix.len());
match event.data { match event.data {
YamlEventData::Alias { .. } => { YamlEventData::Alias { .. } => {
length = analysis length = analysis.anchor.as_ref().map_or(0, |a| a.anchor.len());
.anchor
.as_ref()
.map_or(0, |a| a.anchor.len());
} }
YamlEventData::Scalar { .. } => { YamlEventData::Scalar { .. } => {
let Some(scalar) = scalar else { let Some(scalar) = scalar else {
@ -921,39 +903,27 @@ fn yaml_emitter_process_scalar(
) -> Result<(), EmitterError> { ) -> Result<(), EmitterError> {
match analysis.style { match analysis.style {
YAML_PLAIN_SCALAR_STYLE => { YAML_PLAIN_SCALAR_STYLE => {
yaml_emitter_write_plain_scalar( yaml_emitter_write_plain_scalar(emitter, analysis.value, !emitter.simple_key_context)
emitter,
analysis.value,
!emitter.simple_key_context,
)
}
YAML_SINGLE_QUOTED_SCALAR_STYLE => {
yaml_emitter_write_single_quoted_scalar(
emitter,
analysis.value,
!emitter.simple_key_context,
)
}
YAML_DOUBLE_QUOTED_SCALAR_STYLE => {
yaml_emitter_write_double_quoted_scalar(
emitter,
analysis.value,
!emitter.simple_key_context,
)
}
YAML_LITERAL_SCALAR_STYLE => {
yaml_emitter_write_literal_scalar(emitter, analysis.value)
}
YAML_FOLDED_SCALAR_STYLE => {
yaml_emitter_write_folded_scalar(emitter, analysis.value)
} }
YAML_SINGLE_QUOTED_SCALAR_STYLE => yaml_emitter_write_single_quoted_scalar(
emitter,
analysis.value,
!emitter.simple_key_context,
),
YAML_DOUBLE_QUOTED_SCALAR_STYLE => yaml_emitter_write_double_quoted_scalar(
emitter,
analysis.value,
!emitter.simple_key_context,
),
YAML_LITERAL_SCALAR_STYLE => yaml_emitter_write_literal_scalar(emitter, analysis.value),
YAML_FOLDED_SCALAR_STYLE => yaml_emitter_write_folded_scalar(emitter, analysis.value),
YAML_ANY_SCALAR_STYLE => unreachable!("No scalar style chosen"), YAML_ANY_SCALAR_STYLE => unreachable!("No scalar style chosen"),
} }
} }
fn yaml_emitter_analyze_version_directive( fn yaml_emitter_analyze_version_directive(
emitter: &mut yaml_emitter_t, emitter: &mut yaml_emitter_t,
version_directive: &yaml_version_directive_t, version_directive: yaml_version_directive_t,
) -> Result<(), EmitterError> { ) -> Result<(), EmitterError> {
if version_directive.major != 1 || version_directive.minor != 1 && version_directive.minor != 2 if version_directive.major != 1 || version_directive.minor != 1 && version_directive.minor != 2
{ {
@ -1570,7 +1540,7 @@ fn yaml_emitter_write_double_quoted_scalar(
(b'U', 8) (b'U', 8)
}; };
PUT(emitter, prefix)?; PUT(emitter, prefix)?;
let mut k = ((width - 1) * 4) as i32; let mut k = (width - 1) * 4;
let value_0 = ch as u32; let value_0 = ch as u32;
while k >= 0 { while k >= 0 {
let digit = (value_0 >> k) & 0x0F; let digit = (value_0 >> k) & 0x0F;
@ -1640,10 +1610,7 @@ fn yaml_emitter_write_block_scalar_hints(
if !is_break(ch) { if !is_break(ch) {
chomp_hint = Some("-"); chomp_hint = Some("-");
} else if next.is_none() { } else if is_breakz(next) {
chomp_hint = Some("+");
emitter.open_ended = 2;
} else if is_break(next) {
chomp_hint = Some("+"); chomp_hint = Some("+");
emitter.open_ended = 2; emitter.open_ended = 2;
} }

View file

@ -11,7 +11,7 @@
clippy::cast_lossless, clippy::cast_lossless,
clippy::cast_possible_truncation, clippy::cast_possible_truncation,
clippy::cast_possible_wrap, clippy::cast_possible_wrap,
clippy::cast_ptr_alignment, // clippy::cast_ptr_alignment,
clippy::cast_sign_loss, clippy::cast_sign_loss,
clippy::collapsible_if, clippy::collapsible_if,
clippy::doc_markdown, clippy::doc_markdown,
@ -20,22 +20,18 @@
clippy::items_after_statements, clippy::items_after_statements,
clippy::let_underscore_untyped, clippy::let_underscore_untyped,
clippy::manual_range_contains, clippy::manual_range_contains,
clippy::manual_swap,
clippy::missing_panics_doc, clippy::missing_panics_doc,
clippy::missing_safety_doc, clippy::missing_safety_doc,
clippy::missing_errors_doc,
clippy::module_name_repetitions, clippy::module_name_repetitions,
clippy::must_use_candidate, clippy::must_use_candidate,
clippy::needless_pass_by_value,
clippy::nonminimal_bool, clippy::nonminimal_bool,
clippy::ptr_as_ptr,
clippy::redundant_else,
clippy::similar_names, clippy::similar_names,
clippy::single_match, clippy::struct_excessive_bools,
clippy::single_match_else,
clippy::too_many_arguments, clippy::too_many_arguments,
clippy::too_many_lines, clippy::too_many_lines,
clippy::unnecessary_cast, clippy::unnecessary_wraps
clippy::unreadable_literal,
clippy::while_immutable_condition, // https://github.com/rust-lang/rust-clippy/issues/3548
)] )]
extern crate alloc; extern crate alloc;
@ -260,9 +256,9 @@ foo: bar
yaml_emitter_set_output_string(&mut emitter, &mut output); yaml_emitter_set_output_string(&mut emitter, &mut output);
let mut event = yaml_event_t::default(); let mut event = yaml_event_t::default();
yaml_stream_start_event_initialize(&mut event, YAML_UTF8_ENCODING).unwrap(); yaml_stream_start_event_initialize(&mut event, YAML_UTF8_ENCODING);
yaml_emitter_emit(&mut emitter, core::mem::take(&mut event)).unwrap(); yaml_emitter_emit(&mut emitter, core::mem::take(&mut event)).unwrap();
yaml_document_start_event_initialize(&mut event, None, &[], true).unwrap(); yaml_document_start_event_initialize(&mut event, None, &[], true);
yaml_emitter_emit(&mut emitter, core::mem::take(&mut event)).unwrap(); yaml_emitter_emit(&mut emitter, core::mem::take(&mut event)).unwrap();
yaml_scalar_event_initialize( yaml_scalar_event_initialize(
&mut event, &mut event,
@ -272,12 +268,11 @@ foo: bar
true, true,
true, true,
YAML_PLAIN_SCALAR_STYLE, YAML_PLAIN_SCALAR_STYLE,
) );
.unwrap();
yaml_emitter_emit(&mut emitter, core::mem::take(&mut event)).unwrap(); yaml_emitter_emit(&mut emitter, core::mem::take(&mut event)).unwrap();
yaml_document_end_event_initialize(&mut event, true).unwrap(); yaml_document_end_event_initialize(&mut event, true);
yaml_emitter_emit(&mut emitter, core::mem::take(&mut event)).unwrap(); yaml_emitter_emit(&mut emitter, core::mem::take(&mut event)).unwrap();
yaml_stream_end_event_initialize(&mut event).unwrap(); yaml_stream_end_event_initialize(&mut event);
yaml_emitter_emit(&mut emitter, core::mem::take(&mut event)).unwrap(); yaml_emitter_emit(&mut emitter, core::mem::take(&mut event)).unwrap();
assert_eq!( assert_eq!(

View file

@ -67,7 +67,7 @@ fn yaml_parser_update_raw_buffer(parser: &mut yaml_parser_t) -> Result<(), Reade
.expect("non-null read handler") .expect("non-null read handler")
.read(write_to)?; .read(write_to)?;
let valid_size = len_before + size_read as usize; let valid_size = len_before + size_read;
parser.raw_buffer.truncate(valid_size); parser.raw_buffer.truncate(valid_size);
if size_read == 0 { if size_read == 0 {
parser.eof = true; parser.eof = true;
@ -107,13 +107,12 @@ fn read_char_utf8(raw: &mut VecDeque<u8>) -> Option<Result<char, Utf8Error>> {
if raw.len() < width { if raw.len() < width {
return Some(Err(Utf8Error::Incomplete)); return Some(Err(Utf8Error::Incomplete));
} }
for i in 1..width { for (i, trailing) in raw.iter().enumerate().take(width).skip(1) {
let trailing = raw[i];
if trailing & 0xc0 != 0x80 { if trailing & 0xc0 != 0x80 {
return Some(Err(Utf8Error::InvalidTrailingOctet(i))); return Some(Err(Utf8Error::InvalidTrailingOctet(i)));
} }
value <<= 6; value <<= 6;
value += trailing as u32 & 0x3f; value += *trailing as u32 & 0x3f;
} }
if !(width == 1 if !(width == 1
|| width == 2 && value >= 0x80 || width == 2 && value >= 0x80
@ -246,7 +245,6 @@ pub(crate) fn yaml_parser_update_buffer(
); );
} else { } else {
// Read more // Read more
();
} }
} }
Some(Err(Utf8Error::InvalidLeadingOctet)) => { Some(Err(Utf8Error::InvalidLeadingOctet)) => {
@ -305,7 +303,6 @@ pub(crate) fn yaml_parser_update_buffer(
); );
} else { } else {
// Read more // Read more
();
} }
} }
Some(Err(Utf16Error::UnexpectedLowSurrogateArea(value))) => { Some(Err(Utf16Error::UnexpectedLowSurrogateArea(value))) => {

View file

@ -339,7 +339,10 @@ fn yaml_parser_increase_flow_level(parser: &mut yaml_parser_t) -> Result<(), Sca
}, },
}; };
parser.simple_keys.push(empty_simple_key); parser.simple_keys.push(empty_simple_key);
assert!(!(parser.flow_level == libc::c_int::MAX), "parser.flow_level integer overflow"); assert!(
!(parser.flow_level == libc::c_int::MAX),
"parser.flow_level integer overflow"
);
parser.flow_level += 1; parser.flow_level += 1;
Ok(()) Ok(())
} }
@ -363,7 +366,10 @@ fn yaml_parser_roll_indent(
} }
if (parser.indent as libc::c_long) < column { if (parser.indent as libc::c_long) < column {
parser.indents.push(parser.indent); parser.indents.push(parser.indent);
assert!(!(column > ptrdiff_t::from(libc::c_int::MAX)), "integer overflow"); assert!(
!(column > ptrdiff_t::from(libc::c_int::MAX)),
"integer overflow"
);
parser.indent = column as libc::c_int; parser.indent = column as libc::c_int;
let token = yaml_token_t { let token = yaml_token_t {
data, data,
@ -948,7 +954,7 @@ fn yaml_parser_scan_anchor(
scan_alias_instead_of_anchor: bool, scan_alias_instead_of_anchor: bool,
) -> Result<(), ScannerError> { ) -> Result<(), ScannerError> {
let mut length: libc::c_int = 0; let mut length: libc::c_int = 0;
let mut string = String::new(); let mut string = String::new();
let start_mark: yaml_mark_t = parser.mark; let start_mark: yaml_mark_t = parser.mark;
SKIP(parser); SKIP(parser);
@ -1004,7 +1010,7 @@ fn yaml_parser_scan_tag(
) -> Result<(), ScannerError> { ) -> Result<(), ScannerError> {
let mut handle; let mut handle;
let mut suffix; let mut suffix;
let start_mark: yaml_mark_t = parser.mark; let start_mark: yaml_mark_t = parser.mark;
CACHE(parser, 2_u64)?; CACHE(parser, 2_u64)?;
@ -1116,57 +1122,55 @@ fn yaml_parser_scan_tag_uri(
let mut length = head.len(); let mut length = head.len();
let mut string = String::new(); let mut string = String::new();
loop { if length > 1 {
if length > 1 { string = String::from(&head[1..]);
string = String::from(&head[1..]); }
} CACHE(parser, 1_u64)?;
CACHE(parser, 1_u64)?;
while IS_ALPHA!(parser.buffer) while IS_ALPHA!(parser.buffer)
|| CHECK!(parser.buffer, ';') || CHECK!(parser.buffer, ';')
|| CHECK!(parser.buffer, '/') || CHECK!(parser.buffer, '/')
|| CHECK!(parser.buffer, '?') || CHECK!(parser.buffer, '?')
|| CHECK!(parser.buffer, ':') || CHECK!(parser.buffer, ':')
|| CHECK!(parser.buffer, '@') || CHECK!(parser.buffer, '@')
|| CHECK!(parser.buffer, '&') || CHECK!(parser.buffer, '&')
|| CHECK!(parser.buffer, '=') || CHECK!(parser.buffer, '=')
|| CHECK!(parser.buffer, '+') || CHECK!(parser.buffer, '+')
|| CHECK!(parser.buffer, '$') || CHECK!(parser.buffer, '$')
|| CHECK!(parser.buffer, '.') || CHECK!(parser.buffer, '.')
|| CHECK!(parser.buffer, '%') || CHECK!(parser.buffer, '%')
|| CHECK!(parser.buffer, '!') || CHECK!(parser.buffer, '!')
|| CHECK!(parser.buffer, '~') || CHECK!(parser.buffer, '~')
|| CHECK!(parser.buffer, '*') || CHECK!(parser.buffer, '*')
|| CHECK!(parser.buffer, '\'') || CHECK!(parser.buffer, '\'')
|| CHECK!(parser.buffer, '(') || CHECK!(parser.buffer, '(')
|| CHECK!(parser.buffer, ')') || CHECK!(parser.buffer, ')')
|| uri_char || uri_char
&& (CHECK!(parser.buffer, ',') && (CHECK!(parser.buffer, ',')
|| CHECK!(parser.buffer, '[') || CHECK!(parser.buffer, '[')
|| CHECK!(parser.buffer, ']')) || CHECK!(parser.buffer, ']'))
{ {
if CHECK!(parser.buffer, '%') { if CHECK!(parser.buffer, '%') {
yaml_parser_scan_uri_escapes(parser, directive, start_mark, &mut string)?; yaml_parser_scan_uri_escapes(parser, directive, start_mark, &mut string)?;
} else {
READ_STRING(parser, &mut string);
}
length = length.force_add(1);
CACHE(parser, 1_u64)?;
}
if length == 0 {
return yaml_parser_set_scanner_error(
parser,
if directive {
"while parsing a %TAG directive"
} else {
"while parsing a tag"
},
start_mark,
"did not find expected tag URI",
);
} else { } else {
return Ok(string); READ_STRING(parser, &mut string);
} }
length = length.force_add(1);
CACHE(parser, 1_u64)?;
}
if length == 0 {
yaml_parser_set_scanner_error(
parser,
if directive {
"while parsing a %TAG directive"
} else {
"while parsing a tag"
},
start_mark,
"did not find expected tag URI",
)
} else {
Ok(string)
} }
} }
@ -1460,7 +1464,6 @@ fn yaml_parser_scan_flow_scalar(
token: &mut yaml_token_t, token: &mut yaml_token_t,
single: bool, single: bool,
) -> Result<(), ScannerError> { ) -> Result<(), ScannerError> {
let mut string = String::new(); let mut string = String::new();
let mut leading_break = String::new(); let mut leading_break = String::new();
let mut trailing_breaks = String::new(); let mut trailing_breaks = String::new();
@ -1613,10 +1616,8 @@ fn yaml_parser_scan_flow_scalar(
"did not find expected hexdecimal number", "did not find expected hexdecimal number",
); );
} else { } else {
value = value = (value << 4)
(value << 4) .force_add(AS_HEX_AT!(parser.buffer, k as usize));
.force_add(AS_HEX_AT!(parser.buffer, k as usize)
as libc::c_uint);
k = k.force_add(1); k = k.force_add(1);
} }
} }