mirror of
https://github.com/simonask/libyaml-safer
synced 2024-11-22 19:33:03 +00:00
Make yaml_string_t always owning
This commit is contained in:
parent
b96790c782
commit
f26c0c28ae
3 changed files with 42 additions and 23 deletions
|
@ -1836,7 +1836,7 @@ unsafe fn yaml_emitter_write_double_quoted_scalar(
|
|||
|
||||
unsafe fn yaml_emitter_write_block_scalar_hints(
|
||||
emitter: &mut yaml_emitter_t,
|
||||
mut string: yaml_string_t,
|
||||
string: &yaml_string_t,
|
||||
) -> Result<(), ()> {
|
||||
let mut indent_hint: [libc::c_char; 2] = [0; 2];
|
||||
let mut chomp_hint: *const libc::c_char = ptr::null::<libc::c_char>();
|
||||
|
@ -1846,29 +1846,30 @@ unsafe fn yaml_emitter_write_block_scalar_hints(
|
|||
yaml_emitter_write_indicator(emitter, indent_hint.as_mut_ptr(), false, false, false)?;
|
||||
}
|
||||
emitter.open_ended = 0;
|
||||
string.pointer = string.end;
|
||||
if string.start == string.pointer {
|
||||
let mut pointer = string.end;
|
||||
|
||||
if string.start == pointer {
|
||||
chomp_hint = b"-\0" as *const u8 as *const libc::c_char;
|
||||
} else {
|
||||
loop {
|
||||
string.pointer = string.pointer.wrapping_offset(-1);
|
||||
if !(*string.pointer & 0xC0 == 0x80) {
|
||||
pointer = pointer.wrapping_offset(-1);
|
||||
if !(*pointer & 0xC0 == 0x80) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if !IS_BREAK!(string) {
|
||||
if !IS_BREAK_PTR!(pointer) {
|
||||
chomp_hint = b"-\0" as *const u8 as *const libc::c_char;
|
||||
} else if string.start == string.pointer {
|
||||
} else if string.start == pointer {
|
||||
chomp_hint = b"+\0" as *const u8 as *const libc::c_char;
|
||||
emitter.open_ended = 2;
|
||||
} else {
|
||||
loop {
|
||||
string.pointer = string.pointer.wrapping_offset(-1);
|
||||
if !(*string.pointer & 0xC0 == 0x80) {
|
||||
pointer = pointer.wrapping_offset(-1);
|
||||
if !(*pointer & 0xC0 == 0x80) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if IS_BREAK!(string) {
|
||||
if IS_BREAK_PTR!(pointer) {
|
||||
chomp_hint = b"+\0" as *const u8 as *const libc::c_char;
|
||||
emitter.open_ended = 2;
|
||||
}
|
||||
|
@ -1894,7 +1895,7 @@ unsafe fn yaml_emitter_write_literal_scalar(
|
|||
false,
|
||||
false,
|
||||
)?;
|
||||
yaml_emitter_write_block_scalar_hints(emitter, string)?;
|
||||
yaml_emitter_write_block_scalar_hints(emitter, &string)?;
|
||||
PUT_BREAK(emitter)?;
|
||||
emitter.indention = true;
|
||||
emitter.whitespace = true;
|
||||
|
@ -1930,7 +1931,7 @@ unsafe fn yaml_emitter_write_folded_scalar(
|
|||
false,
|
||||
false,
|
||||
)?;
|
||||
yaml_emitter_write_block_scalar_hints(emitter, string)?;
|
||||
yaml_emitter_write_block_scalar_hints(emitter, &string)?;
|
||||
PUT_BREAK(emitter)?;
|
||||
emitter.indention = true;
|
||||
emitter.whitespace = true;
|
||||
|
|
|
@ -90,7 +90,13 @@ macro_rules! JOIN {
|
|||
|
||||
macro_rules! CHECK_AT {
|
||||
($string:expr, $octet:expr, $offset:expr) => {
|
||||
*$string.pointer.offset($offset as isize) == $octet
|
||||
CHECK_AT_PTR!($string.pointer, $octet, $offset)
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! CHECK_AT_PTR {
|
||||
($pointer:expr, $octet:expr, $offset:expr) => {
|
||||
*$pointer.offset($offset as isize) == $octet
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -252,15 +258,22 @@ macro_rules! IS_BLANK {
|
|||
|
||||
macro_rules! IS_BREAK_AT {
|
||||
($string:expr, $offset:expr) => {
|
||||
CHECK_AT!($string, b'\r', $offset)
|
||||
|| CHECK_AT!($string, b'\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)
|
||||
IS_BREAK_AT_PTR!($string.pointer, $offset)
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! IS_BREAK_AT_PTR {
|
||||
($pointer:expr, $offset:expr) => {
|
||||
CHECK_AT_PTR!($pointer, b'\r', $offset)
|
||||
|| CHECK_AT_PTR!($pointer, b'\n', $offset)
|
||||
|| CHECK_AT_PTR!($pointer, b'\xC2', $offset)
|
||||
&& CHECK_AT_PTR!($pointer, b'\x85', $offset + 1)
|
||||
|| CHECK_AT_PTR!($pointer, b'\xE2', $offset)
|
||||
&& CHECK_AT_PTR!($pointer, b'\x80', $offset + 1)
|
||||
&& CHECK_AT_PTR!($pointer, b'\xA8', $offset + 2)
|
||||
|| CHECK_AT_PTR!($pointer, b'\xE2', $offset)
|
||||
&& CHECK_AT_PTR!($pointer, b'\x80', $offset + 1)
|
||||
&& CHECK_AT_PTR!($pointer, b'\xA9', $offset + 2)
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -270,6 +283,12 @@ macro_rules! IS_BREAK {
|
|||
};
|
||||
}
|
||||
|
||||
macro_rules! IS_BREAK_PTR {
|
||||
($pointer:expr) => {
|
||||
IS_BREAK_AT_PTR!($pointer, 0)
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! IS_CRLF {
|
||||
($string:expr) => {
|
||||
CHECK_AT!($string, b'\r', 0) && CHECK_AT!($string, b'\n', 1)
|
||||
|
|
|
@ -1219,7 +1219,6 @@ pub(crate) struct unnamed_yaml_emitter_t_scalar_data {
|
|||
pub style: yaml_scalar_style_t,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
#[repr(C)]
|
||||
pub(crate) struct yaml_string_t {
|
||||
pub start: *mut yaml_char_t,
|
||||
|
|
Loading…
Reference in a new issue