mirror of
https://github.com/simonask/libyaml-safer
synced 2024-11-26 13:20:24 +00:00
Merge pull request #11 from dtolnay/cintcast
Remove some needless libc::c_int casts
This commit is contained in:
commit
5132ad2a57
6 changed files with 70 additions and 79 deletions
34
src/api.rs
34
src/api.rs
|
@ -562,25 +562,25 @@ unsafe fn yaml_check_utf8(start: *const yaml_char_t, length: size_t) -> Success
|
|||
let mut value: libc::c_uint;
|
||||
let mut k: size_t;
|
||||
octet = *pointer;
|
||||
let width: libc::c_uint = if octet as libc::c_int & 0x80 == 0 {
|
||||
let width: libc::c_uint = if octet & 0x80 == 0 {
|
||||
1
|
||||
} else if octet as libc::c_int & 0xE0 == 0xC0 {
|
||||
} else if octet & 0xE0 == 0xC0 {
|
||||
2
|
||||
} else if octet as libc::c_int & 0xF0 == 0xE0 {
|
||||
} else if octet & 0xF0 == 0xE0 {
|
||||
3
|
||||
} else if octet as libc::c_int & 0xF8 == 0xF0 {
|
||||
} else if octet & 0xF8 == 0xF0 {
|
||||
4
|
||||
} else {
|
||||
0
|
||||
} as libc::c_uint;
|
||||
value = if octet as libc::c_int & 0x80 == 0 {
|
||||
octet as libc::c_int & 0x7F
|
||||
} else if octet as libc::c_int & 0xE0 == 0xC0 {
|
||||
octet as libc::c_int & 0x1F
|
||||
} else if octet as libc::c_int & 0xF0 == 0xE0 {
|
||||
octet as libc::c_int & 0xF
|
||||
} else if octet as libc::c_int & 0xF8 == 0xF0 {
|
||||
octet as libc::c_int & 0x7
|
||||
value = if octet & 0x80 == 0 {
|
||||
octet & 0x7F
|
||||
} else if octet & 0xE0 == 0xC0 {
|
||||
octet & 0x1F
|
||||
} else if octet & 0xF0 == 0xE0 {
|
||||
octet & 0xF
|
||||
} else if octet & 0xF8 == 0xF0 {
|
||||
octet & 0x7
|
||||
} else {
|
||||
0
|
||||
} as libc::c_uint;
|
||||
|
@ -593,10 +593,10 @@ unsafe fn yaml_check_utf8(start: *const yaml_char_t, length: size_t) -> Success
|
|||
k = 1_u64;
|
||||
while k < width as libc::c_ulong {
|
||||
octet = *pointer.wrapping_offset(k as isize);
|
||||
if octet as libc::c_int & 0xC0 != 0x80 {
|
||||
if octet & 0xC0 != 0x80 {
|
||||
return FAIL;
|
||||
}
|
||||
value = (value << 6).wrapping_add((octet as libc::c_int & 0x3F) as libc::c_uint);
|
||||
value = (value << 6).wrapping_add((octet & 0x3F) as libc::c_uint);
|
||||
k = k.wrapping_add(1);
|
||||
}
|
||||
if !(width == 1
|
||||
|
@ -1501,7 +1501,7 @@ pub unsafe fn yaml_document_add_scalar(
|
|||
(*node).data.scalar.style = style;
|
||||
if PUSH!(addr_of_mut!(context), (*document).nodes, *node).ok {
|
||||
return (*document).nodes.top.c_offset_from((*document).nodes.start)
|
||||
as libc::c_long as libc::c_int;
|
||||
as libc::c_int;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1567,7 +1567,7 @@ pub unsafe fn yaml_document_add_sequence(
|
|||
(*node).data.sequence.style = style;
|
||||
if PUSH!(addr_of_mut!(context), (*document).nodes, *node).ok {
|
||||
return (*document).nodes.top.c_offset_from((*document).nodes.start)
|
||||
as libc::c_long as libc::c_int;
|
||||
as libc::c_int;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1632,7 +1632,7 @@ pub unsafe fn yaml_document_add_mapping(
|
|||
(*node).data.mapping.style = style;
|
||||
if PUSH!(addr_of_mut!(context), (*document).nodes, *node).ok {
|
||||
return (*document).nodes.top.c_offset_from((*document).nodes.start)
|
||||
as libc::c_long as libc::c_int;
|
||||
as libc::c_int;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1398,13 +1398,13 @@ unsafe fn yaml_emitter_analyze_tag_directive(
|
|||
b"tag handle must not be empty\0" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
}
|
||||
if *handle.start as libc::c_int != '!' as i32 {
|
||||
if *handle.start != b'!' {
|
||||
return yaml_emitter_set_emitter_error(
|
||||
emitter,
|
||||
b"tag handle must start with '!'\0" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
}
|
||||
if *handle.end.wrapping_offset(-1_isize) as libc::c_int != '!' as i32 {
|
||||
if *handle.end.wrapping_offset(-1_isize) != b'!' {
|
||||
return yaml_emitter_set_emitter_error(
|
||||
emitter,
|
||||
b"tag handle must end with '!'\0" as *const u8 as *const libc::c_char,
|
||||
|
@ -2317,8 +2317,7 @@ unsafe fn yaml_emitter_write_block_scalar_hints(
|
|||
let mut indent_hint: [libc::c_char; 2] = [0; 2];
|
||||
let mut chomp_hint: *const libc::c_char = ptr::null::<libc::c_char>();
|
||||
if IS_SPACE!(string) || IS_BREAK!(string) {
|
||||
indent_hint[0_usize] =
|
||||
('0' as i32 + (*emitter).best_indent as libc::c_char as libc::c_int) as libc::c_char;
|
||||
indent_hint[0_usize] = (b'0' as libc::c_int + (*emitter).best_indent) as libc::c_char;
|
||||
indent_hint[1_usize] = '\0' as libc::c_char;
|
||||
if yaml_emitter_write_indicator(emitter, indent_hint.as_mut_ptr(), false, false, false).fail
|
||||
{
|
||||
|
@ -2332,7 +2331,7 @@ unsafe fn yaml_emitter_write_block_scalar_hints(
|
|||
} else {
|
||||
loop {
|
||||
string.pointer = string.pointer.wrapping_offset(-1);
|
||||
if !(*string.pointer as libc::c_int & 0xC0 == 0x80) {
|
||||
if !(*string.pointer & 0xC0 == 0x80) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -2344,7 +2343,7 @@ unsafe fn yaml_emitter_write_block_scalar_hints(
|
|||
} else {
|
||||
loop {
|
||||
string.pointer = string.pointer.wrapping_offset(-1);
|
||||
if !(*string.pointer as libc::c_int & 0xC0 == 0x80) {
|
||||
if !(*string.pointer & 0xC0 == 0x80) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -384,7 +384,7 @@ unsafe fn yaml_parser_load_scalar(
|
|||
.nodes
|
||||
.top
|
||||
.c_offset_from((*(*parser).document).nodes.start)
|
||||
as libc::c_long as libc::c_int;
|
||||
as libc::c_int;
|
||||
if yaml_parser_register_anchor(parser, index, (*event).data.scalar.anchor).fail
|
||||
{
|
||||
return FAIL;
|
||||
|
@ -461,7 +461,7 @@ unsafe fn yaml_parser_load_sequence(
|
|||
.nodes
|
||||
.top
|
||||
.c_offset_from((*(*parser).document).nodes.start)
|
||||
as libc::c_long as libc::c_int;
|
||||
as libc::c_int;
|
||||
if yaml_parser_register_anchor(
|
||||
parser,
|
||||
index,
|
||||
|
@ -572,7 +572,7 @@ unsafe fn yaml_parser_load_mapping(
|
|||
.nodes
|
||||
.top
|
||||
.c_offset_from((*(*parser).document).nodes.start)
|
||||
as libc::c_long as libc::c_int;
|
||||
as libc::c_int;
|
||||
if yaml_parser_register_anchor(
|
||||
parser,
|
||||
index,
|
||||
|
|
|
@ -212,13 +212,13 @@ pub(crate) unsafe fn yaml_parser_update_buffer(
|
|||
match (*parser).encoding {
|
||||
YAML_UTF8_ENCODING => {
|
||||
octet = *(*parser).raw_buffer.pointer;
|
||||
width = if octet as libc::c_int & 0x80 == 0 {
|
||||
width = if octet & 0x80 == 0 {
|
||||
1
|
||||
} else if octet as libc::c_int & 0xE0 == 0xC0 {
|
||||
} else if octet & 0xE0 == 0xC0 {
|
||||
2
|
||||
} else if octet as libc::c_int & 0xF0 == 0xE0 {
|
||||
} else if octet & 0xF0 == 0xE0 {
|
||||
3
|
||||
} else if octet as libc::c_int & 0xF8 == 0xF0 {
|
||||
} else if octet & 0xF8 == 0xF0 {
|
||||
4
|
||||
} else {
|
||||
0
|
||||
|
@ -243,21 +243,21 @@ pub(crate) unsafe fn yaml_parser_update_buffer(
|
|||
}
|
||||
incomplete = 1;
|
||||
} else {
|
||||
value = if octet as libc::c_int & 0x80 == 0 {
|
||||
octet as libc::c_int & 0x7F
|
||||
} else if octet as libc::c_int & 0xE0 == 0xC0 {
|
||||
octet as libc::c_int & 0x1F
|
||||
} else if octet as libc::c_int & 0xF0 == 0xE0 {
|
||||
octet as libc::c_int & 0xF
|
||||
} else if octet as libc::c_int & 0xF8 == 0xF0 {
|
||||
octet as libc::c_int & 0x7
|
||||
value = if octet & 0x80 == 0 {
|
||||
octet & 0x7F
|
||||
} else if octet & 0xE0 == 0xC0 {
|
||||
octet & 0x1F
|
||||
} else if octet & 0xF0 == 0xE0 {
|
||||
octet & 0xF
|
||||
} else if octet & 0xF8 == 0xF0 {
|
||||
octet & 0x7
|
||||
} else {
|
||||
0
|
||||
} as libc::c_uint;
|
||||
k = 1_u64;
|
||||
while k < width as libc::c_ulong {
|
||||
octet = *(*parser).raw_buffer.pointer.wrapping_offset(k as isize);
|
||||
if octet as libc::c_int & 0xC0 != 0x80 {
|
||||
if octet & 0xC0 != 0x80 {
|
||||
return yaml_parser_set_reader_error(
|
||||
parser,
|
||||
b"invalid trailing UTF-8 octet\0" as *const u8
|
||||
|
@ -266,8 +266,7 @@ pub(crate) unsafe fn yaml_parser_update_buffer(
|
|||
octet as libc::c_int,
|
||||
);
|
||||
}
|
||||
value = (value << 6)
|
||||
.wrapping_add((octet as libc::c_int & 0x3F) as libc::c_uint);
|
||||
value = (value << 6).wrapping_add((octet & 0x3F) as libc::c_uint);
|
||||
k = k.wrapping_add(1);
|
||||
}
|
||||
if !(width == 1
|
||||
|
|
|
@ -1538,12 +1538,11 @@ unsafe fn yaml_parser_scan_tag(
|
|||
} else if yaml_parser_scan_tag_handle(parser, false, start_mark, addr_of_mut!(handle)).fail
|
||||
{
|
||||
current_block = 17708497480799081542;
|
||||
} else if *handle as libc::c_int == '!' as i32
|
||||
&& *handle.wrapping_offset(1_isize) as libc::c_int != '\0' as i32
|
||||
} else if *handle == b'!'
|
||||
&& *handle.wrapping_offset(1_isize) != b'\0'
|
||||
&& *handle
|
||||
.wrapping_offset(strlen(handle as *mut libc::c_char).wrapping_sub(1_u64) as isize)
|
||||
as libc::c_int
|
||||
== '!' as i32
|
||||
== b'!'
|
||||
{
|
||||
if yaml_parser_scan_tag_uri(
|
||||
parser,
|
||||
|
@ -1578,7 +1577,7 @@ unsafe fn yaml_parser_scan_tag(
|
|||
} else {
|
||||
*handle = b'!';
|
||||
*handle.wrapping_offset(1_isize) = b'\0';
|
||||
if *suffix as libc::c_int == '\0' as i32 {
|
||||
if *suffix == b'\0' {
|
||||
let tmp: *mut yaml_char_t = handle;
|
||||
handle = suffix;
|
||||
suffix = tmp;
|
||||
|
@ -1681,9 +1680,8 @@ unsafe fn yaml_parser_scan_tag_handle(
|
|||
current_block = 5689001924483802034;
|
||||
}
|
||||
} else if directive
|
||||
&& !(*string.start as libc::c_int == '!' as i32
|
||||
&& *string.start.wrapping_offset(1_isize) as libc::c_int
|
||||
== '\0' as i32)
|
||||
&& !(*string.start == b'!'
|
||||
&& *string.start.wrapping_offset(1_isize) == b'\0')
|
||||
{
|
||||
yaml_parser_set_scanner_error(
|
||||
parser,
|
||||
|
@ -1875,13 +1873,13 @@ unsafe fn yaml_parser_scan_uri_escapes(
|
|||
let octet: libc::c_uchar = ((AS_HEX_AT!((*parser).buffer, 1) << 4)
|
||||
+ AS_HEX_AT!((*parser).buffer, 2)) as libc::c_uchar;
|
||||
if width == 0 {
|
||||
width = if octet as libc::c_int & 0x80 == 0 {
|
||||
width = if octet & 0x80 == 0 {
|
||||
1
|
||||
} else if octet as libc::c_int & 0xE0 == 0xC0 {
|
||||
} else if octet & 0xE0 == 0xC0 {
|
||||
2
|
||||
} else if octet as libc::c_int & 0xF0 == 0xE0 {
|
||||
} else if octet & 0xF0 == 0xE0 {
|
||||
3
|
||||
} else if octet as libc::c_int & 0xF8 == 0xF0 {
|
||||
} else if octet & 0xF8 == 0xF0 {
|
||||
4
|
||||
} else {
|
||||
0
|
||||
|
@ -1899,7 +1897,7 @@ unsafe fn yaml_parser_scan_uri_escapes(
|
|||
);
|
||||
return FAIL;
|
||||
}
|
||||
} else if octet as libc::c_int & 0xC0 != 0x80 {
|
||||
} else if octet & 0xC0 != 0x80 {
|
||||
yaml_parser_set_scanner_error(
|
||||
parser,
|
||||
if directive {
|
||||
|
@ -2104,15 +2102,13 @@ unsafe fn yaml_parser_scan_block_scalar(
|
|||
as libc::c_int;
|
||||
if !literal
|
||||
&& *leading_break.start
|
||||
as libc::c_int
|
||||
== '\n' as i32
|
||||
== b'\n'
|
||||
&& leading_blank == 0
|
||||
&& trailing_blank == 0
|
||||
{
|
||||
if *trailing_breaks
|
||||
.start
|
||||
as libc::c_int
|
||||
== '\0' as i32
|
||||
== b'\0'
|
||||
{
|
||||
if STRING_EXTEND!(
|
||||
parser, string
|
||||
|
@ -2440,9 +2436,7 @@ unsafe fn yaml_parser_scan_flow_scalar(
|
|||
current_block = 8114179180390253173;
|
||||
break 's_58;
|
||||
}
|
||||
match *(*parser).buffer.pointer.wrapping_offset(1_isize)
|
||||
as libc::c_int
|
||||
{
|
||||
match *(*parser).buffer.pointer.wrapping_offset(1_isize) {
|
||||
48 => {
|
||||
let fresh542 = string.pointer;
|
||||
string.pointer = string.pointer.wrapping_offset(1);
|
||||
|
@ -2735,8 +2729,8 @@ unsafe fn yaml_parser_scan_flow_scalar(
|
|||
}
|
||||
}
|
||||
if leading_blanks != 0 {
|
||||
if *leading_break.start as libc::c_int == '\n' as i32 {
|
||||
if *trailing_breaks.start as libc::c_int == '\0' as i32 {
|
||||
if *leading_break.start == b'\n' {
|
||||
if *trailing_breaks.start == b'\0' {
|
||||
if STRING_EXTEND!(parser, string).fail {
|
||||
current_block = 8114179180390253173;
|
||||
break;
|
||||
|
@ -2886,9 +2880,8 @@ unsafe fn yaml_parser_scan_plain_scalar(
|
|||
}
|
||||
if leading_blanks != 0 || whitespaces.start != whitespaces.pointer {
|
||||
if leading_blanks != 0 {
|
||||
if *leading_break.start as libc::c_int == '\n' as i32 {
|
||||
if *trailing_breaks.start as libc::c_int == '\0' as i32
|
||||
{
|
||||
if *leading_break.start == b'\n' {
|
||||
if *trailing_breaks.start == b'\0' {
|
||||
if STRING_EXTEND!(parser, string).fail {
|
||||
current_block = 16642808987012640029;
|
||||
break 's_57;
|
||||
|
|
|
@ -65,32 +65,32 @@ pub unsafe fn yaml_emitter_flush(emitter: *mut yaml_emitter_t) -> Success {
|
|||
let mut value: libc::c_uint;
|
||||
let mut k: size_t;
|
||||
octet = *(*emitter).buffer.pointer;
|
||||
let width: libc::c_uint = if octet as libc::c_int & 0x80 == 0 {
|
||||
let width: libc::c_uint = if octet & 0x80 == 0 {
|
||||
1
|
||||
} else if octet as libc::c_int & 0xE0 == 0xC0 {
|
||||
} else if octet & 0xE0 == 0xC0 {
|
||||
2
|
||||
} else if octet as libc::c_int & 0xF0 == 0xE0 {
|
||||
} else if octet & 0xF0 == 0xE0 {
|
||||
3
|
||||
} else if octet as libc::c_int & 0xF8 == 0xF0 {
|
||||
} else if octet & 0xF8 == 0xF0 {
|
||||
4
|
||||
} else {
|
||||
0
|
||||
} as libc::c_uint;
|
||||
value = if octet as libc::c_int & 0x80 == 0 {
|
||||
octet as libc::c_int & 0x7F
|
||||
} else if octet as libc::c_int & 0xE0 == 0xC0 {
|
||||
octet as libc::c_int & 0x1F
|
||||
} else if octet as libc::c_int & 0xF0 == 0xE0 {
|
||||
octet as libc::c_int & 0xF
|
||||
} else if octet as libc::c_int & 0xF8 == 0xF0 {
|
||||
octet as libc::c_int & 0x7
|
||||
value = if octet & 0x80 == 0 {
|
||||
octet & 0x7F
|
||||
} else if octet & 0xE0 == 0xC0 {
|
||||
octet & 0x1F
|
||||
} else if octet & 0xF0 == 0xE0 {
|
||||
octet & 0xF
|
||||
} else if octet & 0xF8 == 0xF0 {
|
||||
octet & 0x7
|
||||
} else {
|
||||
0
|
||||
} as libc::c_uint;
|
||||
k = 1_u64;
|
||||
while k < width as libc::c_ulong {
|
||||
octet = *(*emitter).buffer.pointer.wrapping_offset(k as isize);
|
||||
value = (value << 6).wrapping_add((octet as libc::c_int & 0x3F) as libc::c_uint);
|
||||
value = (value << 6).wrapping_add((octet & 0x3F) as libc::c_uint);
|
||||
k = k.wrapping_add(1);
|
||||
}
|
||||
let fresh5 = addr_of_mut!((*emitter).buffer.pointer);
|
||||
|
|
Loading…
Reference in a new issue