Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…-gdal into no-segfault-mdarray-string
  • Loading branch information
ChristianBeilschmidt committed Aug 16, 2022
2 parents 7daea81 + 8cbf533 commit f5e52fd
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 64 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@

- <https://github.com/georust/gdal/pull/265>

- Remove `PartialEq` from `GdalError`

- <https://github.com/georust/gdal/pull/286>

- Prevent SIGGEGV when reading a string array on an MD Array that is not of type string.

- <https://github.com/georust/gdal/pull/284>
Expand Down
3 changes: 1 addition & 2 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ use gdal_sys::{CPLErr, OGRErr, OGRFieldType, OGRwkbGeometryType};

pub type Result<T> = std::result::Result<T, GdalError>;

#[allow(unknown_lints, clippy::derive_partial_eq_without_eq)] // only enforce `PartialEq` for `GdalError`
#[derive(Clone, PartialEq, Debug, Error)]
#[derive(Clone, Debug, Error)]
pub enum GdalError {
#[error("FfiNulError")]
FfiNulError(#[from] std::ffi::NulError),
Expand Down
18 changes: 9 additions & 9 deletions src/raster/rasterize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,21 +128,21 @@ mod tests {
fn test_rasterizeoptions_as_ptr() {
let c_options = CslStringList::try_from(RasterizeOptions::default()).unwrap();
assert_eq!(
c_options.fetch_name_value("ALL_TOUCHED"),
Ok(Some("FALSE".to_string()))
c_options.fetch_name_value("ALL_TOUCHED").unwrap(),
Some("FALSE".to_string())
);
assert_eq!(c_options.fetch_name_value("BURN_VALUE_FROM"), Ok(None));
assert_eq!(c_options.fetch_name_value("BURN_VALUE_FROM").unwrap(), None);
assert_eq!(
c_options.fetch_name_value("MERGE_ALG"),
Ok(Some("REPLACE".to_string()))
c_options.fetch_name_value("MERGE_ALG").unwrap(),
Some("REPLACE".to_string())
);
assert_eq!(
c_options.fetch_name_value("CHUNKYSIZE"),
Ok(Some("0".to_string()))
c_options.fetch_name_value("CHUNKYSIZE").unwrap(),
Some("0".to_string())
);
assert_eq!(
c_options.fetch_name_value("OPTIM"),
Ok(Some("AUTO".to_string()))
c_options.fetch_name_value("OPTIM").unwrap(),
Some("AUTO".to_string())
);
}
}
Expand Down
58 changes: 30 additions & 28 deletions src/vector/vector_tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,14 +322,14 @@ mod tests {
assert_eq!(feature.field_as_integer64_by_name("railway").unwrap(), None);
assert_eq!(feature.field_as_double_by_name("railway").unwrap(), None);

// test error
assert_eq!(
feature.field_as_string_by_name("not_a_field"),
Err(GdalError::InvalidFieldName {
field_name: "not_a_field".to_owned(),
assert!(matches!(
feature.field_as_string_by_name("not_a_field").unwrap_err(),
GdalError::InvalidFieldName {
field_name,
method_name: "OGR_F_GetFieldIndex",
})
);
}
if field_name == "not_a_field"
));
});
}

Expand Down Expand Up @@ -371,13 +371,13 @@ mod tests {
assert_eq!(feature.field_as_double(railway_field).unwrap(), None);

// test error
assert_eq!(
feature.field_as_string(23),
Err(GdalError::InvalidFieldIndex {
assert!(matches!(
feature.field_as_string(23).unwrap_err(),
GdalError::InvalidFieldIndex {
index: 23,
method_name: "field_as_string",
})
);
}
));
});
}

Expand Down Expand Up @@ -415,20 +415,22 @@ mod tests {
assert_eq!(feature.field_as_datetime(railway_field).unwrap(), None);

// test error
assert_eq!(
feature.field_as_datetime_by_name("not_a_field"),
Err(GdalError::InvalidFieldName {
field_name: "not_a_field".to_owned(),
assert!(matches!(
feature
.field_as_datetime_by_name("not_a_field")
.unwrap_err(),
GdalError::InvalidFieldName {
field_name,
method_name: "OGR_F_GetFieldIndex",
})
);
assert_eq!(
feature.field_as_datetime(23),
Err(GdalError::InvalidFieldIndex {
} if field_name == "not_a_field"
));
assert!(matches!(
feature.field_as_datetime(23).unwrap_err(),
GdalError::InvalidFieldIndex {
index: 23,
method_name: "field_as_datetime",
})
);
}
));
});
}

Expand Down Expand Up @@ -849,13 +851,13 @@ mod tests {
assert_eq!(layer.features().count(), 21);

// force error
assert_eq!(
layer.set_attribute_filter("foo = bar"),
Err(GdalError::OgrError {
assert!(matches!(
layer.set_attribute_filter("foo = bar").unwrap_err(),
GdalError::OgrError {
err: gdal_sys::OGRErr::OGRERR_CORRUPT_DATA,
method_name: "OGR_L_SetAttributeFilter",
})
);
}
));
});
}

Expand Down
54 changes: 29 additions & 25 deletions src/vsi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,13 @@ mod tests {
assert_eq!(bytes, vec![1_u8, 2, 3, 4]);

// mem file must not be there anymore
assert_eq!(
unlink_mem_file(file_name),
Err(GdalError::UnlinkMemFile {
file_name: file_name.to_string()
})
);
assert!(matches!(
unlink_mem_file(file_name).unwrap_err(),
GdalError::UnlinkMemFile {
file_name
}
if file_name == file_name
));
}

#[test]
Expand Down Expand Up @@ -246,13 +247,14 @@ mod tests {

#[test]
fn no_mem_file() {
assert_eq!(
get_vsi_mem_file_bytes_owned("foobar"),
Err(GdalError::NullPointer {
assert!(matches!(
get_vsi_mem_file_bytes_owned("foobar").unwrap_err(),
GdalError::NullPointer {
method_name: "VSIGetMemFileBuffer",
msg: "".to_string(),
})
);
msg,
}
if msg.is_empty()
));
}

#[test]
Expand Down Expand Up @@ -286,20 +288,22 @@ mod tests {
fn unable_to_create() {
let file_name = "";

assert_eq!(
create_mem_file(file_name, vec![1_u8, 2, 3, 4]),
Err(GdalError::NullPointer {
assert!(matches!(
create_mem_file(file_name, vec![1_u8, 2, 3, 4]).unwrap_err(),
GdalError::NullPointer {
method_name: "VSIGetMemFileBuffer",
msg: "".to_string(),
})
);

assert_eq!(
unlink_mem_file(file_name),
Err(GdalError::UnlinkMemFile {
file_name: "".to_string()
})
);
msg,
}
if msg.is_empty()
));

assert!(matches!(
unlink_mem_file(file_name).unwrap_err(),
GdalError::UnlinkMemFile {
file_name,
}
if file_name.is_empty()
));
}

#[test]
Expand Down

0 comments on commit f5e52fd

Please sign in to comment.