mirror of
https://github.com/simonask/libyaml-safer
synced 2024-11-26 21:30:24 +00:00
Factor out CHECK_AT macro
This commit is contained in:
parent
d9917668b4
commit
2e94cd3bdb
3 changed files with 56 additions and 134 deletions
|
@ -1511,16 +1511,8 @@ unsafe fn yaml_emitter_analyze_scalar(
|
|||
(*emitter).scalar_data.block_allowed = 0_i32;
|
||||
return 1_i32;
|
||||
}
|
||||
if *string.pointer as libc::c_int == '-' as i32 as yaml_char_t as libc::c_int
|
||||
&& *string.pointer.wrapping_offset(1_isize) as libc::c_int
|
||||
== '-' as i32 as yaml_char_t as libc::c_int
|
||||
&& *string.pointer.wrapping_offset(2_isize) as libc::c_int
|
||||
== '-' as i32 as yaml_char_t as libc::c_int
|
||||
|| *string.pointer as libc::c_int == '.' as i32 as yaml_char_t as libc::c_int
|
||||
&& *string.pointer.wrapping_offset(1_isize) as libc::c_int
|
||||
== '.' as i32 as yaml_char_t as libc::c_int
|
||||
&& *string.pointer.wrapping_offset(2_isize) as libc::c_int
|
||||
== '.' as i32 as yaml_char_t as libc::c_int
|
||||
if CHECK_AT!(string, '-', 0) && CHECK_AT!(string, '-', 1) && CHECK_AT!(string, '-', 2)
|
||||
|| CHECK_AT!(string, '.', 0) && CHECK_AT!(string, '.', 1) && CHECK_AT!(string, '.', 2)
|
||||
{
|
||||
block_indicators = 1_i32;
|
||||
flow_indicators = 1_i32;
|
||||
|
|
|
@ -122,7 +122,9 @@ macro_rules! JOIN {
|
|||
}
|
||||
|
||||
macro_rules! CHECK_AT {
|
||||
() => {}; // TODO
|
||||
($string:expr, $octet:expr, $offset:expr) => {
|
||||
*$string.pointer.offset($offset as isize) == $octet as yaml_char_t
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! CHECK {
|
||||
|
@ -228,8 +230,7 @@ macro_rules! IS_PRINTABLE {
|
|||
|
||||
macro_rules! IS_Z_AT {
|
||||
($string:expr, $offset:expr) => {
|
||||
*$string.pointer.wrapping_offset($offset as isize) as libc::c_int
|
||||
== '\0' as i32 as yaml_char_t as libc::c_int
|
||||
CHECK_AT!($string, '\0', $offset)
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -241,18 +242,15 @@ macro_rules! IS_Z {
|
|||
|
||||
macro_rules! IS_BOM {
|
||||
($string:expr) => {
|
||||
*$string.pointer as libc::c_int == -17i32 as yaml_char_t as libc::c_int
|
||||
&& *$string.pointer.wrapping_offset(1) as libc::c_int
|
||||
== -69i32 as yaml_char_t as libc::c_int
|
||||
&& *$string.pointer.wrapping_offset(2) as libc::c_int
|
||||
== -65i32 as yaml_char_t as libc::c_int
|
||||
CHECK_AT!($string, b'\xEF', 0)
|
||||
&& CHECK_AT!($string, b'\xBB', 1)
|
||||
&& CHECK_AT!($string, b'\xBF', 2)
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! IS_SPACE_AT {
|
||||
($string:expr, $offset:expr) => {
|
||||
*$string.pointer.wrapping_offset($offset as isize) as libc::c_int
|
||||
== ' ' as i32 as yaml_char_t as libc::c_int
|
||||
CHECK_AT!($string, ' ', $offset)
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -264,8 +262,7 @@ macro_rules! IS_SPACE {
|
|||
|
||||
macro_rules! IS_TAB_AT {
|
||||
($string:expr, $offset:expr) => {
|
||||
*$string.pointer.wrapping_offset($offset as isize) as libc::c_int
|
||||
== '\t' as i32 as yaml_char_t as libc::c_int
|
||||
CHECK_AT!($string, '\t', $offset)
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -289,26 +286,15 @@ macro_rules! IS_BLANK {
|
|||
|
||||
macro_rules! IS_BREAK_AT {
|
||||
($string:expr, $offset:expr) => {
|
||||
*$string.pointer.wrapping_offset($offset as isize) as libc::c_int
|
||||
== '\r' as i32 as yaml_char_t as libc::c_int
|
||||
|| *$string.pointer.wrapping_offset($offset as isize) as libc::c_int
|
||||
== '\n' as i32 as yaml_char_t as libc::c_int
|
||||
|| *$string.pointer.wrapping_offset($offset as isize) as libc::c_int
|
||||
== -62i32 as yaml_char_t as libc::c_int
|
||||
&& *$string.pointer.wrapping_offset($offset as isize + 1) as libc::c_int
|
||||
== -123i32 as yaml_char_t as libc::c_int
|
||||
|| *$string.pointer.wrapping_offset($offset as isize) as libc::c_int
|
||||
== -30i32 as yaml_char_t as libc::c_int
|
||||
&& *$string.pointer.wrapping_offset($offset as isize + 1) as libc::c_int
|
||||
== -128i32 as yaml_char_t as libc::c_int
|
||||
&& *$string.pointer.wrapping_offset($offset as isize + 2) as libc::c_int
|
||||
== -88i32 as yaml_char_t as libc::c_int
|
||||
|| *$string.pointer.wrapping_offset($offset as isize) as libc::c_int
|
||||
== -30i32 as yaml_char_t as libc::c_int
|
||||
&& *$string.pointer.wrapping_offset($offset as isize + 1) as libc::c_int
|
||||
== -128i32 as yaml_char_t as libc::c_int
|
||||
&& *$string.pointer.wrapping_offset($offset as isize + 2) as libc::c_int
|
||||
== -87i32 as yaml_char_t as libc::c_int
|
||||
CHECK_AT!($string, '\r', $offset)
|
||||
|| CHECK_AT!($string, '\n', $offset)
|
||||
|| CHECK_AT!($string, b'\xC2', $offset) && CHECK_AT!($string, b'\x85', $offset + 1)
|
||||
|| CHECK_AT!($string, b'\xE2', $offset)
|
||||
&& CHECK_AT!($string, b'\x80', $offset + 1)
|
||||
&& CHECK_AT!($string, b'\xA8', $offset + 2)
|
||||
|| CHECK_AT!($string, b'\xE2', $offset)
|
||||
&& CHECK_AT!($string, b'\x80', $offset + 1)
|
||||
&& CHECK_AT!($string, b'\xA9', $offset + 2)
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -320,9 +306,7 @@ macro_rules! IS_BREAK {
|
|||
|
||||
macro_rules! IS_CRLF {
|
||||
($string:expr) => {
|
||||
*$string.pointer as libc::c_int == '\r' as i32 as yaml_char_t as libc::c_int
|
||||
&& *$string.pointer.offset(1) as libc::c_int
|
||||
== '\n' as i32 as yaml_char_t as libc::c_int
|
||||
CHECK_AT!($string, '\r', 0) && CHECK_AT!($string, '\n', 1)
|
||||
};
|
||||
}
|
||||
|
||||
|
|
124
src/scanner.rs
124
src/scanner.rs
|
@ -89,11 +89,7 @@ macro_rules! READ {
|
|||
macro_rules! READ_LINE {
|
||||
($parser:expr, $string:expr) => {
|
||||
if STRING_EXTEND!($parser, $string) != 0 {
|
||||
if *((*$parser).buffer.pointer) as libc::c_int
|
||||
== '\r' as i32 as yaml_char_t as libc::c_int
|
||||
&& *((*$parser).buffer.pointer).wrapping_offset(1_isize) as libc::c_int
|
||||
== '\n' as i32 as yaml_char_t as libc::c_int
|
||||
{
|
||||
if CHECK_AT!((*$parser).buffer, '\r', 0) && CHECK_AT!((*$parser).buffer, '\n', 1) {
|
||||
let fresh484 = addr_of_mut!($string.pointer);
|
||||
let fresh485 = *fresh484;
|
||||
*fresh484 = (*fresh484).wrapping_offset(1);
|
||||
|
@ -107,10 +103,7 @@ macro_rules! READ_LINE {
|
|||
*fresh488 = (*fresh488).wrapping_add(1);
|
||||
let fresh489 = addr_of_mut!((*$parser).unread);
|
||||
*fresh489 = (*fresh489 as libc::c_ulong).wrapping_sub(2_u64) as size_t as size_t;
|
||||
} else if *((*$parser).buffer.pointer) as libc::c_int
|
||||
== '\r' as i32 as yaml_char_t as libc::c_int
|
||||
|| *((*$parser).buffer.pointer) as libc::c_int
|
||||
== '\n' as i32 as yaml_char_t as libc::c_int
|
||||
} else if CHECK_AT!((*$parser).buffer, '\r', 0) || CHECK_AT!((*$parser).buffer, '\n', 0)
|
||||
{
|
||||
let fresh490 = addr_of_mut!($string.pointer);
|
||||
let fresh491 = *fresh490;
|
||||
|
@ -125,10 +118,8 @@ macro_rules! READ_LINE {
|
|||
*fresh494 = (*fresh494).wrapping_add(1);
|
||||
let fresh495 = addr_of_mut!((*$parser).unread);
|
||||
*fresh495 = (*fresh495).wrapping_sub(1);
|
||||
} else if *((*$parser).buffer.pointer) as libc::c_int
|
||||
== -62i32 as yaml_char_t as libc::c_int
|
||||
&& *((*$parser).buffer.pointer).wrapping_offset(1_isize) as libc::c_int
|
||||
== -123i32 as yaml_char_t as libc::c_int
|
||||
} else if CHECK_AT!((*$parser).buffer, b'\xC2', 0)
|
||||
&& CHECK_AT!((*$parser).buffer, b'\x85', 1)
|
||||
{
|
||||
let fresh496 = addr_of_mut!($string.pointer);
|
||||
let fresh497 = *fresh496;
|
||||
|
@ -143,14 +134,10 @@ macro_rules! READ_LINE {
|
|||
*fresh500 = (*fresh500).wrapping_add(1);
|
||||
let fresh501 = addr_of_mut!((*$parser).unread);
|
||||
*fresh501 = (*fresh501).wrapping_sub(1);
|
||||
} else if *((*$parser).buffer.pointer) as libc::c_int
|
||||
== -30i32 as yaml_char_t as libc::c_int
|
||||
&& *((*$parser).buffer.pointer).wrapping_offset(1_isize) as libc::c_int
|
||||
== -128i32 as yaml_char_t as libc::c_int
|
||||
&& (*((*$parser).buffer.pointer).wrapping_offset(2_isize) as libc::c_int
|
||||
== -88i32 as yaml_char_t as libc::c_int
|
||||
|| *((*$parser).buffer.pointer).wrapping_offset(2_isize) as libc::c_int
|
||||
== -87i32 as yaml_char_t as libc::c_int)
|
||||
} else if CHECK_AT!((*$parser).buffer, b'\xE2', 0)
|
||||
&& CHECK_AT!((*$parser).buffer, b'\x80', 1)
|
||||
&& (CHECK_AT!((*$parser).buffer, b'\xA8', 2)
|
||||
|| CHECK_AT!((*$parser).buffer, b'\xA9', 2))
|
||||
{
|
||||
let fresh502 = addr_of_mut!((*$parser).buffer.pointer);
|
||||
let fresh503 = *fresh502;
|
||||
|
@ -310,21 +297,17 @@ unsafe fn yaml_parser_fetch_next_token(parser: *mut yaml_parser_t) -> libc::c_in
|
|||
return yaml_parser_fetch_directive(parser);
|
||||
}
|
||||
if (*parser).mark.column == 0_u64
|
||||
&& *((*parser).buffer.pointer) as libc::c_int == '-' as i32 as yaml_char_t as libc::c_int
|
||||
&& *((*parser).buffer.pointer).wrapping_offset(1_isize) as libc::c_int
|
||||
== '-' as i32 as yaml_char_t as libc::c_int
|
||||
&& *((*parser).buffer.pointer).wrapping_offset(2_isize) as libc::c_int
|
||||
== '-' as i32 as yaml_char_t as libc::c_int
|
||||
&& CHECK_AT!((*parser).buffer, '-', 0)
|
||||
&& CHECK_AT!((*parser).buffer, '-', 1)
|
||||
&& CHECK_AT!((*parser).buffer, '-', 2)
|
||||
&& IS_BLANKZ_AT!((*parser).buffer, 3)
|
||||
{
|
||||
return yaml_parser_fetch_document_indicator(parser, YAML_DOCUMENT_START_TOKEN);
|
||||
}
|
||||
if (*parser).mark.column == 0_u64
|
||||
&& *((*parser).buffer.pointer) as libc::c_int == '.' as i32 as yaml_char_t as libc::c_int
|
||||
&& *((*parser).buffer.pointer).wrapping_offset(1_isize) as libc::c_int
|
||||
== '.' as i32 as yaml_char_t as libc::c_int
|
||||
&& *((*parser).buffer.pointer).wrapping_offset(2_isize) as libc::c_int
|
||||
== '.' as i32 as yaml_char_t as libc::c_int
|
||||
&& CHECK_AT!((*parser).buffer, '.', 0)
|
||||
&& CHECK_AT!((*parser).buffer, '.', 1)
|
||||
&& CHECK_AT!((*parser).buffer, '.', 2)
|
||||
&& IS_BLANKZ_AT!((*parser).buffer, 3)
|
||||
{
|
||||
return yaml_parser_fetch_document_indicator(parser, YAML_DOCUMENT_END_TOKEN);
|
||||
|
@ -1587,9 +1570,7 @@ unsafe fn yaml_parser_scan_tag(
|
|||
let end_mark: yaml_mark_t;
|
||||
let start_mark: yaml_mark_t = (*parser).mark;
|
||||
if !(CACHE!(parser, 2_u64) == 0) {
|
||||
if *((*parser).buffer.pointer).wrapping_offset(1_isize) as libc::c_int
|
||||
== '<' as i32 as yaml_char_t as libc::c_int
|
||||
{
|
||||
if CHECK_AT!((*parser).buffer, '<', 1) {
|
||||
handle = yaml_malloc(1_u64) as *mut yaml_char_t;
|
||||
if handle.is_null() {
|
||||
current_block = 17708497480799081542;
|
||||
|
@ -2441,22 +2422,12 @@ unsafe fn yaml_parser_scan_flow_scalar(
|
|||
break;
|
||||
}
|
||||
if (*parser).mark.column == 0_u64
|
||||
&& (*((*parser).buffer.pointer) as libc::c_int
|
||||
== '-' as i32 as yaml_char_t as libc::c_int
|
||||
&& *((*parser).buffer.pointer).wrapping_offset(1_isize)
|
||||
as libc::c_int
|
||||
== '-' as i32 as yaml_char_t as libc::c_int
|
||||
&& *((*parser).buffer.pointer).wrapping_offset(2_isize)
|
||||
as libc::c_int
|
||||
== '-' as i32 as yaml_char_t as libc::c_int
|
||||
|| *((*parser).buffer.pointer) as libc::c_int
|
||||
== '.' as i32 as yaml_char_t as libc::c_int
|
||||
&& *((*parser).buffer.pointer).wrapping_offset(1_isize)
|
||||
as libc::c_int
|
||||
== '.' as i32 as yaml_char_t as libc::c_int
|
||||
&& *((*parser).buffer.pointer).wrapping_offset(2_isize)
|
||||
as libc::c_int
|
||||
== '.' as i32 as yaml_char_t as libc::c_int)
|
||||
&& (CHECK_AT!((*parser).buffer, '-', 0)
|
||||
&& CHECK_AT!((*parser).buffer, '-', 1)
|
||||
&& CHECK_AT!((*parser).buffer, '-', 2)
|
||||
|| CHECK_AT!((*parser).buffer, '.', 0)
|
||||
&& CHECK_AT!((*parser).buffer, '.', 1)
|
||||
&& CHECK_AT!((*parser).buffer, '.', 2))
|
||||
&& IS_BLANKZ_AT!((*parser).buffer, 3)
|
||||
{
|
||||
yaml_parser_set_scanner_error(
|
||||
|
@ -2488,11 +2459,8 @@ unsafe fn yaml_parser_scan_flow_scalar(
|
|||
leading_blanks = 0_i32;
|
||||
while !IS_BLANKZ!((*parser).buffer) {
|
||||
if single != 0
|
||||
&& *((*parser).buffer.pointer) as libc::c_int
|
||||
== '\'' as i32 as yaml_char_t as libc::c_int
|
||||
&& *((*parser).buffer.pointer).wrapping_offset(1_isize)
|
||||
as libc::c_int
|
||||
== '\'' as i32 as yaml_char_t as libc::c_int
|
||||
&& CHECK_AT!((*parser).buffer, '\'', 0)
|
||||
&& CHECK_AT!((*parser).buffer, '\'', 1)
|
||||
{
|
||||
if STRING_EXTEND!(parser, string) == 0 {
|
||||
current_block = 8114179180390253173;
|
||||
|
@ -2955,22 +2923,12 @@ unsafe fn yaml_parser_scan_plain_scalar(
|
|||
break;
|
||||
}
|
||||
if (*parser).mark.column == 0_u64
|
||||
&& (*((*parser).buffer.pointer) as libc::c_int
|
||||
== '-' as i32 as yaml_char_t as libc::c_int
|
||||
&& *((*parser).buffer.pointer).wrapping_offset(1_isize)
|
||||
as libc::c_int
|
||||
== '-' as i32 as yaml_char_t as libc::c_int
|
||||
&& *((*parser).buffer.pointer).wrapping_offset(2_isize)
|
||||
as libc::c_int
|
||||
== '-' as i32 as yaml_char_t as libc::c_int
|
||||
|| *((*parser).buffer.pointer) as libc::c_int
|
||||
== '.' as i32 as yaml_char_t as libc::c_int
|
||||
&& *((*parser).buffer.pointer).wrapping_offset(1_isize)
|
||||
as libc::c_int
|
||||
== '.' as i32 as yaml_char_t as libc::c_int
|
||||
&& *((*parser).buffer.pointer).wrapping_offset(2_isize)
|
||||
as libc::c_int
|
||||
== '.' as i32 as yaml_char_t as libc::c_int)
|
||||
&& (CHECK_AT!((*parser).buffer, '-', 0)
|
||||
&& CHECK_AT!((*parser).buffer, '-', 1)
|
||||
&& CHECK_AT!((*parser).buffer, '-', 2)
|
||||
|| CHECK_AT!((*parser).buffer, '.', 0)
|
||||
&& CHECK_AT!((*parser).buffer, '.', 1)
|
||||
&& CHECK_AT!((*parser).buffer, '.', 2))
|
||||
&& IS_BLANKZ_AT!((*parser).buffer, 3)
|
||||
{
|
||||
current_block = 6281126495347172768;
|
||||
|
@ -2986,24 +2944,12 @@ unsafe fn yaml_parser_scan_plain_scalar(
|
|||
if (*parser).flow_level != 0
|
||||
&& *((*parser).buffer.pointer) as libc::c_int
|
||||
== ':' as i32 as yaml_char_t as libc::c_int
|
||||
&& (*((*parser).buffer.pointer).wrapping_offset(1_isize)
|
||||
as libc::c_int
|
||||
== ',' as i32 as yaml_char_t as libc::c_int
|
||||
|| *((*parser).buffer.pointer).wrapping_offset(1_isize)
|
||||
as libc::c_int
|
||||
== '?' as i32 as yaml_char_t as libc::c_int
|
||||
|| *((*parser).buffer.pointer).wrapping_offset(1_isize)
|
||||
as libc::c_int
|
||||
== '[' as i32 as yaml_char_t as libc::c_int
|
||||
|| *((*parser).buffer.pointer).wrapping_offset(1_isize)
|
||||
as libc::c_int
|
||||
== ']' as i32 as yaml_char_t as libc::c_int
|
||||
|| *((*parser).buffer.pointer).wrapping_offset(1_isize)
|
||||
as libc::c_int
|
||||
== '{' as i32 as yaml_char_t as libc::c_int
|
||||
|| *((*parser).buffer.pointer).wrapping_offset(1_isize)
|
||||
as libc::c_int
|
||||
== '}' as i32 as yaml_char_t as libc::c_int)
|
||||
&& (CHECK_AT!((*parser).buffer, ',', 1)
|
||||
|| CHECK_AT!((*parser).buffer, '?', 1)
|
||||
|| CHECK_AT!((*parser).buffer, '[', 1)
|
||||
|| CHECK_AT!((*parser).buffer, ']', 1)
|
||||
|| CHECK_AT!((*parser).buffer, '{', 1)
|
||||
|| CHECK_AT!((*parser).buffer, '}', 1))
|
||||
{
|
||||
yaml_parser_set_scanner_error(
|
||||
parser,
|
||||
|
|
Loading…
Reference in a new issue