mirror of
https://github.com/simonask/libyaml-safer
synced 2024-11-22 19:33:03 +00:00
Get rid of some unsafe paranoia
This commit is contained in:
parent
a31d33f9cb
commit
4630800a8a
3 changed files with 9 additions and 75 deletions
|
@ -127,7 +127,7 @@ pub(crate) unsafe fn unsafe_main(
|
|||
break Err("Memory error: Not enough memory for creating an event".into());
|
||||
}
|
||||
if yaml_emitter_emit(&mut emitter, event).is_err() {
|
||||
break Err(match (*emitter).error {
|
||||
break Err(match emitter.error {
|
||||
YAML_MEMORY_ERROR => "Memory error: Not enough memory for emitting".into(),
|
||||
YAML_WRITER_ERROR => format!(
|
||||
"Writer error: {}",
|
||||
|
|
|
@ -61,12 +61,12 @@ pub(crate) unsafe fn unsafe_main(
|
|||
loop {
|
||||
if yaml_parser_parse(&mut parser, &mut event).is_err() {
|
||||
let mut error = format!("Parse error: {}", parser.problem.unwrap_or(""));
|
||||
if parser.problem_mark.line != 0 || (*parser).problem_mark.column != 0 {
|
||||
if parser.problem_mark.line != 0 || parser.problem_mark.column != 0 {
|
||||
let _ = write!(
|
||||
error,
|
||||
"\nLine: {} Column: {}",
|
||||
((*parser).problem_mark.line).wrapping_add(1_u64),
|
||||
((*parser).problem_mark.column).wrapping_add(1_u64),
|
||||
(parser.problem_mark.line).wrapping_add(1_u64),
|
||||
(parser.problem_mark.column).wrapping_add(1_u64),
|
||||
);
|
||||
}
|
||||
yaml_parser_delete(&mut parser);
|
||||
|
|
76
src/yaml.rs
76
src/yaml.rs
|
@ -3,8 +3,7 @@ use alloc::string::String;
|
|||
use alloc::vec::Vec;
|
||||
|
||||
use crate::libc;
|
||||
use core::ops::Deref;
|
||||
use core::ptr::{self, addr_of};
|
||||
use core::ptr;
|
||||
|
||||
pub use self::yaml_encoding_t::*;
|
||||
pub use core::primitive::{i64 as ptrdiff_t, u64 as size_t, u8 as yaml_char_t};
|
||||
|
@ -672,40 +671,19 @@ pub struct yaml_alias_data_t {
|
|||
#[non_exhaustive]
|
||||
pub struct yaml_parser_t {
|
||||
/// Error type.
|
||||
#[cfg(doc)]
|
||||
pub error: yaml_error_type_t,
|
||||
#[cfg(not(doc))]
|
||||
pub(crate) error: yaml_error_type_t,
|
||||
/// Error description.
|
||||
#[cfg(doc)]
|
||||
pub problem: *const libc::c_char,
|
||||
#[cfg(not(doc))]
|
||||
pub(crate) problem: Option<&'static str>,
|
||||
pub problem: Option<&'static str>,
|
||||
/// The byte about which the problem occured.
|
||||
#[cfg(doc)]
|
||||
pub problem_offset: size_t,
|
||||
#[cfg(not(doc))]
|
||||
pub(crate) problem_offset: size_t,
|
||||
/// The problematic value (-1 is none).
|
||||
#[cfg(doc)]
|
||||
pub problem_value: libc::c_int,
|
||||
#[cfg(not(doc))]
|
||||
pub(crate) problem_value: libc::c_int,
|
||||
/// The problem position.
|
||||
#[cfg(doc)]
|
||||
pub problem_mark: yaml_mark_t,
|
||||
#[cfg(not(doc))]
|
||||
pub(crate) problem_mark: yaml_mark_t,
|
||||
/// The error context.
|
||||
#[cfg(doc)]
|
||||
pub context: *const libc::c_char,
|
||||
#[cfg(not(doc))]
|
||||
pub(crate) context: Option<&'static str>,
|
||||
pub context: Option<&'static str>,
|
||||
/// The context position.
|
||||
#[cfg(doc)]
|
||||
pub context_mark: yaml_mark_t,
|
||||
#[cfg(not(doc))]
|
||||
pub(crate) context_mark: yaml_mark_t,
|
||||
/// Read handler.
|
||||
pub(crate) read_handler: Option<yaml_read_handler_t>,
|
||||
/// A pointer for passing to the read handler.
|
||||
|
@ -805,33 +783,6 @@ impl Default for yaml_parser_t {
|
|||
}
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[non_exhaustive]
|
||||
pub struct yaml_parser_t_prefix {
|
||||
/// Error type.
|
||||
pub error: yaml_error_type_t,
|
||||
/// Error description.
|
||||
pub problem: Option<&'static str>,
|
||||
/// The byte about which the problem occured.
|
||||
pub problem_offset: size_t,
|
||||
/// The problematic value (-1 is none).
|
||||
pub problem_value: libc::c_int,
|
||||
/// The problem position.
|
||||
pub problem_mark: yaml_mark_t,
|
||||
/// The error context.
|
||||
pub context: Option<&'static str>,
|
||||
/// The context position.
|
||||
pub context_mark: yaml_mark_t,
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
impl Deref for yaml_parser_t {
|
||||
type Target = yaml_parser_t_prefix;
|
||||
fn deref(&self) -> &Self::Target {
|
||||
unsafe { &*addr_of!(*self).cast() }
|
||||
}
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub(crate) struct unnamed_yaml_parser_t_input_string {
|
||||
/// The string start pointer.
|
||||
|
@ -926,9 +877,9 @@ pub(crate) struct yaml_anchors_t {
|
|||
#[non_exhaustive]
|
||||
pub struct yaml_emitter_t {
|
||||
/// Error type.
|
||||
pub(crate) error: yaml_error_type_t,
|
||||
pub error: yaml_error_type_t,
|
||||
/// Error description.
|
||||
pub(crate) problem: Option<&'static str>,
|
||||
pub problem: Option<&'static str>,
|
||||
/// Write handler.
|
||||
pub(crate) write_handler: Option<yaml_write_handler_t>,
|
||||
/// A pointer for passing to the write handler.
|
||||
|
@ -1048,23 +999,6 @@ impl Default for yaml_emitter_t {
|
|||
}
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[non_exhaustive]
|
||||
pub struct yaml_emitter_t_prefix {
|
||||
/// Error type.
|
||||
pub error: yaml_error_type_t,
|
||||
/// Error description.
|
||||
pub problem: Option<&'static str>,
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
impl Deref for yaml_emitter_t {
|
||||
type Target = yaml_emitter_t_prefix;
|
||||
fn deref(&self) -> &Self::Target {
|
||||
unsafe { &*addr_of!(*self).cast() }
|
||||
}
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub(crate) struct unnamed_yaml_emitter_t_output_string {
|
||||
/// The buffer pointer.
|
||||
|
|
Loading…
Reference in a new issue