Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dimensions getter when no dimensions are available #303

Merged
merged 1 commit into from Sep 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion CHANGES.md
Expand Up @@ -2,10 +2,14 @@

## Unreleased

- Added new content to README.md and root rust docs.
- Added new content to `README.md` and the root docs.

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

- Fixed a crash in `Group::dimensions` and `MDArray::dimensions` when no dimensions exist

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

## 0.13

- Add prebuild bindings for GDAL 3.5
Expand Down
18 changes: 12 additions & 6 deletions src/raster/mdarray.rs
Expand Up @@ -103,9 +103,12 @@ impl<'a> MDArray<'a> {

let c_dimensions = unsafe { GDALMDArrayGetDimensions(self.c_mdarray, &mut num_dimensions) };

// `num_dimensions` is `0`, we can safely return an empty vector
// `GDALMDArrayGetDimensions` does not state that errors can occur
if num_dimensions > 0 && c_dimensions.is_null() {
// If `num_dimensions` is `0`, we can safely return an empty vector.
// `GDALMDArrayGetDimensions` does not state that errors can occur.
if num_dimensions == 0 {
return Ok(Vec::new());
}
if c_dimensions.is_null() {
return Err(_last_null_pointer_err("GDALMDArrayGetDimensions"));
}

Expand Down Expand Up @@ -532,9 +535,12 @@ impl<'a> Group<'a> {
let c_dimensions =
GDALGroupGetDimensions(self.c_group, &mut num_dimensions, options.as_ptr());

// `num_dimensions` is `0`, we can safely return an empty vector
// `GDALGroupGetDimensions` does not state that errors can occur
if num_dimensions > 0 && c_dimensions.is_null() {
// If `num_dimensions` is `0`, we can safely return an empty vector.
// `GDALGroupGetDimensions` does not state that errors can occur.
if num_dimensions == 0 {
return Ok(Vec::new());
}
if c_dimensions.is_null() {
return Err(_last_null_pointer_err("GDALGroupGetDimensions"));
}

Expand Down