Skip to content

Commit

Permalink
Don't treat 2d array as 1d array, fixing UBSan complaint in `CPP_test…
Browse files Browse the repository at this point in the history
…hdf5`
  • Loading branch information
seanm committed Apr 8, 2021
1 parent 6e1d518 commit 31645f3
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions c++/test/ttypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,6 @@ static void
test_named()
{
static hsize_t ds_size[2] = {10, 20};
hsize_t i;
unsigned attr_data[10][20];
DataType * ds_type = NULL;

Expand Down Expand Up @@ -726,8 +725,11 @@ test_named()

// It should be possible to define an attribute for the named type
Attribute attr1 = itype.createAttribute("attr1", PredType::NATIVE_UCHAR, space);
for (i = 0; i < ds_size[0] * ds_size[1]; i++)
attr_data[0][i] = (int)i; /*tricky*/
for (hsize_t i = 0; i < ds_size[0]; i++) {
for (hsize_t j = 0; j < ds_size[1]; j++) {
attr_data[i][j] = (unsigned)(i * ds_size[1]] + j);
}
}
attr1.write(PredType::NATIVE_UINT, attr_data);
attr1.close();

Expand Down

0 comments on commit 31645f3

Please sign in to comment.