Skip to content

Commit

Permalink
Review fixes part 1
Browse files Browse the repository at this point in the history
  • Loading branch information
micahsnyder committed Nov 1, 2023
1 parent e407e48 commit b258ad5
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 159 deletions.
83 changes: 45 additions & 38 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions libclamav_rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ sha1 = "0.10.5"
unicode-segmentation = "1.10.1"
bindgen = "0.65"
onenote_parser = { git = "https://github.com/micahsnyder/onenote.rs.git", branch = "CLAM-2329-new-from-slice" }
hex-literal = "0.4.1"

[lib]
crate-type = ["staticlib"]
Expand Down
2 changes: 1 addition & 1 deletion libclamav_rust/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ fn execute_bindgen() -> Result<(), &'static str> {
// Silence code-style warnings for generated bindings.
.raw_line("#![allow(non_snake_case, non_camel_case_types, non_upper_case_globals)]")
// Make the bindings pretty.
.rustfmt_bindings(true)
.formatter(bindgen::Formatter::Rustfmt)
// Disable the layout tests.
// We're commiting to source control. Pointer width, integer size, etc
// are probably not the same when generated as when compiled.
Expand Down
22 changes: 11 additions & 11 deletions libclamav_rust/src/ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@
use std::convert::TryInto;
use std::slice;

use thiserror::Error;
use thiserror;

use crate::fmap::FMap;
use crate::sys::cli_ctx;
use crate::util::optional_cstring;

/// OneDumpError enumerates all possible errors returned by this library.
#[derive(Error, Debug)]
pub enum CtxError {
/// Error enumerates all possible errors returned by this library.
#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error("Invalid format")]
Format,

Expand All @@ -53,9 +53,9 @@ pub enum CtxError {
/// # Safety
///
/// Must be a valid ctx pointer.
pub fn sub_filepath(ctx: *mut cli_ctx) -> Result<Option<&'static str>, CtxError> {
pub fn sub_filepath(ctx: *mut cli_ctx) -> Result<Option<&'static str>, Error> {
if ctx.is_null() {
return Err(CtxError::NullPointer("ctx"));
return Err(Error::NullPointer("ctx"));
}

Ok(optional_cstring(unsafe { *ctx }.sub_filepath))
Expand All @@ -66,9 +66,9 @@ pub fn sub_filepath(ctx: *mut cli_ctx) -> Result<Option<&'static str>, CtxError>
/// # Safety
///
/// Must be a valid ctx pointer.
pub fn target_filepath(ctx: *mut cli_ctx) -> Result<Option<&'static str>, CtxError> {
pub fn target_filepath(ctx: *mut cli_ctx) -> Result<Option<&'static str>, Error> {
if ctx.is_null() {
return Err(CtxError::NullPointer("ctx"));
return Err(Error::NullPointer("ctx"));
}

Ok(optional_cstring(unsafe { *ctx }.target_filepath))
Expand All @@ -79,9 +79,9 @@ pub fn target_filepath(ctx: *mut cli_ctx) -> Result<Option<&'static str>, CtxErr
/// # Safety
///
/// Must be a valid ctx pointer.
pub fn current_fmap(ctx: *mut cli_ctx) -> Result<FMap, CtxError> {
pub fn current_fmap(ctx: *mut cli_ctx) -> Result<FMap, Error> {
if ctx.is_null() {
return Err(CtxError::NullPointer("ctx"));
return Err(Error::NullPointer("ctx"));
}

let recursion_stack_size = unsafe { *ctx }.recursion_stack_size as usize;
Expand All @@ -92,5 +92,5 @@ pub fn current_fmap(ctx: *mut cli_ctx) -> Result<FMap, CtxError> {

let current_level = recursion_stack[recursion_level];

current_level.fmap.try_into().map_err(|_| CtxError::BadMap)
current_level.fmap.try_into().map_err(|_| Error::BadMap)
}
Loading

0 comments on commit b258ad5

Please sign in to comment.