Skip to content

Commit

Permalink
Update maximum dimension checks in HDF5 file functions
Browse files Browse the repository at this point in the history
  • Loading branch information
ulises-jeremias committed Feb 4, 2024
1 parent 60a7722 commit dd16294
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
28 changes: 14 additions & 14 deletions inout/h5/hdf5_nix.c.v
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ pub fn open_file(filename string) !Hdf5File {

// read_dataset1d reads a 1-d numeric array (vector) from a named HDF5 dataset in an HDF5 file.
// Replaces the value of the array.
// Maximum dimension is math.max_i32 or less (this is checked).
// Maximum dimension is max_i32 or less (this is checked).
pub fn (f &Hdf5File) read_dataset1d[T](dset_name string, mut dataset []T) {
mut rank := 0
mut class_id := Hdf5ClassT(0)
Expand All @@ -242,7 +242,7 @@ pub fn (f &Hdf5File) read_dataset1d[T](dset_name string, mut dataset []T) {
&class_id, &type_size)
assert errc >= 0
assert curdims[0] > 0
assert curdims[0] < math.max_i32
assert curdims[0] < max_i32

dtype := hdftype(dataset[0])
// note: V dims are int while hdf5 dims are u64
Expand All @@ -257,8 +257,8 @@ pub fn (f &Hdf5File) read_dataset1d[T](dset_name string, mut dataset []T) {

// read_dataset2d reads a 2-d numeric array from a named HDF5 dataset in an HDF5 file.
// Replaces the value of the array.
// Maximum of any dimension is math.max_i32 or less (this is checked).
// Maximum total elements is also math.max_i32.
// Maximum of any dimension is max_i32 or less (this is checked).
// Maximum total elements is also max_i32.
pub fn (f &Hdf5File) read_dataset2d[T](dset_name string, mut dataset [][]T) {
mut rank := 0
mut class_id := Hdf5ClassT(0)
Expand All @@ -274,8 +274,8 @@ pub fn (f &Hdf5File) read_dataset2d[T](dset_name string, mut dataset [][]T) {
assert errc >= 0
assert curdims[0] > 0
assert curdims[1] > 0
assert curdims[0] < math.max_i32
assert curdims[1] < math.max_i32
assert curdims[0] < max_i32
assert curdims[1] < max_i32

dtype := hdftype(dataset[0][0])
mut y := make1type[T](int(curdims[0] * curdims[1]))
Expand All @@ -291,8 +291,8 @@ pub fn (f &Hdf5File) read_dataset2d[T](dset_name string, mut dataset [][]T) {

// read_dataset3d reads a 3-d numeric array from a named HDF5 dataset in an HDF5 file.
// Replaces the value of the array with correctly dimensioned array.
// Maximum of any dimension is math.max_i32 or less (this is checked).
// Maximum total elements is also math.max_i32.
// Maximum of any dimension is max_i32 or less (this is checked).
// Maximum total elements is also max_i32.
pub fn (f &Hdf5File) read_dataset3d[T](dset_name string, mut dataset [][][]T) {
mut rank := 0
mut class_id := Hdf5ClassT(0)
Expand All @@ -309,9 +309,9 @@ pub fn (f &Hdf5File) read_dataset3d[T](dset_name string, mut dataset [][][]T) {
assert curdims[0] > 0
assert curdims[1] > 0
assert curdims[2] > 0
assert curdims[0] < math.max_i32
assert curdims[1] < math.max_i32
assert curdims[2] < math.max_i32
assert curdims[0] < max_i32
assert curdims[1] < max_i32
assert curdims[2] < max_i32

dtype := hdftype(dataset[0][0][0])
mut y := make1type[T](int(curdims[0] * curdims[1] * curdims[2]))
Expand Down Expand Up @@ -584,7 +584,7 @@ pub fn (f &Hdf5File) read_attribute[T](dset_name string, attr_name string, mut a

// read_attribute1d reads a 1-d numeric array (vector) from a named HDF5 dataset and named attribute in an HDF5 file.
// Replaces the value of the given array.
// Maximum dimension is math.max_i32 or less (this is checked).
// Maximum dimension is max_i32 or less (this is checked).
pub fn (f &Hdf5File) read_attribute1d[T](dset_name string, attr_name string, mut attr_value []T) !bool {
mut rank := 0
mut class_id := Hdf5ClassT(0)
Expand All @@ -603,8 +603,8 @@ pub fn (f &Hdf5File) read_attribute1d[T](dset_name string, attr_name string, mut
&class_id, &type_size)
assert errc >= 0
assert curdims[0] > 0
assert curdims[0] <= math.max_i32
if curdims[0] > math.max_i32 {
assert curdims[0] <= max_i32
if curdims[0] > max_i32 {
return false
}

Expand Down
4 changes: 2 additions & 2 deletions prime/prime_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ fn test_is_prime() {
// true
assert is_prime(7_691)
assert is_prime(524_287)
assert is_prime(int(math.max_i32))
assert is_prime(int(max_i32))

// false
assert is_prime(int(math.max_i32) - 1) == false
assert is_prime(int(max_i32) - 1) == false
}

fn test_prime_sieve() {
Expand Down

0 comments on commit dd16294

Please sign in to comment.