From 8f5738e829d917c667c095dfb217b3a6cccf48f0 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Wed, 27 Jul 2022 17:58:45 -0700 Subject: [PATCH] Remove some needless libc::c_int casts --- src/api.rs | 34 +++++++++++++++++----------------- src/emitter.rs | 11 +++++------ src/loader.rs | 6 +++--- src/reader.rs | 29 ++++++++++++++--------------- src/scanner.rs | 43 ++++++++++++++++++------------------------- src/writer.rs | 26 +++++++++++++------------- 6 files changed, 70 insertions(+), 79 deletions(-) diff --git a/src/api.rs b/src/api.rs index 2af525e..c5f667a 100644 --- a/src/api.rs +++ b/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; } } } diff --git a/src/emitter.rs b/src/emitter.rs index 9fe4fef..a445884 100644 --- a/src/emitter.rs +++ b/src/emitter.rs @@ -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::(); 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; } } diff --git a/src/loader.rs b/src/loader.rs index 9f9c799..6deccd0 100644 --- a/src/loader.rs +++ b/src/loader.rs @@ -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, diff --git a/src/reader.rs b/src/reader.rs index 61ca390..f9f569b 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -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 diff --git a/src/scanner.rs b/src/scanner.rs index abc86f3..a8eea95 100644 --- a/src/scanner.rs +++ b/src/scanner.rs @@ -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; diff --git a/src/writer.rs b/src/writer.rs index fb9ab5e..57d1387 100644 --- a/src/writer.rs +++ b/src/writer.rs @@ -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);