Skip to content

Commit

Permalink
Fix dimensions getter when no dimensions are available
Browse files Browse the repository at this point in the history
  • Loading branch information
lnicola committed Sep 2, 2022
1 parent 604c41f commit c46f032
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

- Fixed a crash in `Group::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
Original file line number Diff line number Diff line change
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

0 comments on commit c46f032

Please sign in to comment.